﻿using System;
using System.Collections.Generic;
using System.Windows.Media.TextFormatting;
using netDxf;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Tables;

namespace TestDxfDocument
{
    class Multi_tooth_threaded_inserts
    {
        private const double Pi = Math.PI;

        public static void _TriangularInsert(Dictionary<string, Object> data)    //镶边正三边形刀片，适用于T形刀片
        {
            DxfDocument dxf = new DxfDocument();

            Layer contour = new Layer("contour");//轮廓层
            Layer dimensioning = new Layer("dimensioning");//尺寸层
            Layer refin = new Layer("refin");//基准线/内轮廓/虚线
            Layer center = new Layer("center");//中心线
            Layer textlayer = new Layer("textlayer");//文本层
            Layer hatching = new Layer("hatching");//填充层
            Layer additionalline = new Layer("additionalline");//附加线
            Layer cutting = new Layer("cutting");//切削层
            fun.SetLayer(dxf);

            double offset = 10;
            double textsize = 3.5;

            double tic = Convert.ToDouble(data["ic"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0 && tic < 9)
            {
                scale = 3.0;
            }
            else if (scale == 0 && tic < 20)
            {
                scale = 2.5;
            }
            else if (scale == 0)
            {
                scale = 2.0;
            }


            double pi = Math.PI;
            double DIM = Convert.ToDouble(data["dim"]);
            double ic = Convert.ToDouble(data["ic"]) * scale;
            double s = Convert.ToDouble(data["s"]) * scale;
            double d1 = Convert.ToDouble(data["d1"]) * scale;
            double re = Convert.ToDouble(data["re"]) * scale;
            double epsr = Convert.ToDouble(data["epsr"]) * pi / 180;
            double an = Convert.ToDouble(data["an"]);
            int ifs = (int)Convert.ToDecimal(data["ifs"]);
            int cb = (int)Convert.ToDecimal(data["cb"]);
            string path = Convert.ToString(data["path"]);
            //double le = Convert.ToDouble(data["le"]) * scale;
            double le = ic / Math.Tan(30 * pi / 180);
            double ictc = Convert.ToDouble(data["ictc"]) * scale;
            double stc = Convert.ToDouble(data["stc"]) * scale;
            double d1tc = 0;
            double dxc = Convert.ToDouble(data["dxc"]) * scale;
            double l1 = Convert.ToDouble(data["l1"]) * scale;
            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);

            /*
            double pi = Math.PI;
            double DIM =0;
            double ic = 12.7;
            double s = 4.76;
            double d1 = 3.81 ;
            double re = 1.2;
            double epsr = 60*pi/180;
            double an = 0;
            int ifs = 2;
            int cb = 0;
            string path = Convert.ToString(data["path"]);
            double le = ic/Math .Tan (30*pi/180);
            double ictc = 0;
            double stc = 0;
            double d1tc = 0;
            double dxc =0.8;
            double l1 = 0.8;
            */
            /*
            double scale = 3;
            double pi = Math.PI;
            double DIM = 1;
            double ic = 3.97*scale;
            double s = 1.59 * scale;
            double d1 = 0;
            double re = 0.4 * scale;
            double epsr = 60 * pi / 180;
            double an = 10;
            int ifs = 2;
            int cb = 0;
            string path = Convert.ToString(data["path"]);
            double le = ic / Math.Tan(30 * pi / 180);
            double ictc = 0;
            double stc = 0;
            double d1tc = 0;
            double dxc = 0.8*scale ;
            double l1 = 0.8*scale ;
            */
            Vector2 p1 = new Vector2(0, 0);

            Vector2 p0 = fun.Polar(p1, pi / 6, ic);
            Vector2 p2 = fun.Polar(p1, 0, le);
            Vector2 p3 = fun.Polar(p1, pi / 3, le);
            Vector2 p1p = fun.Polar(p1, pi / 6, 2 * re);
            Vector2 p2p = fun.Polar(p2, 5 * pi / 6, 2 * re);
            Vector2 p3p = fun.Polar(p3, -0.5 * pi, 2 * re);
            Vector2 p4 = fun.Polar(p1p, 5 * pi / 6, re);
            Vector2 p5 = fun.Polar(p1p, -0.5 * pi, re);
            Vector2 p6 = fun.Polar(p2p, -0.5 * pi, re);
            Vector2 p7 = fun.Polar(p2p, pi / 6, re);
            Vector2 p8 = fun.Polar(p3p, pi / 6, re);
            Vector2 p9 = fun.Polar(p3p, 5 * pi / 6, re);

            Vector2 p20 = fun.Polar(p0, 0, (2) * le);
            Vector2 p21 = new Vector2(p20.X, p3p.Y + re);

            Vector2 p22 = fun.Polar(p21, pi + an * pi / 180, s / Math.Cos(an * pi / 180));
            Vector2 p24 = new Vector2(p20.X, p1.Y);
            Vector2 p23 = fun.Polar(p24, pi - an * pi / 180, s / Math.Cos(an * pi / 180));

            Vector2 v1 = fun.Polar(p0, -150 * pi / 180, ic / 2 / Math.Cos(60 * pi / 180) * dxc);
            Vector2 v2 = fun.Polar(p0, -30 * pi / 180, ic / 2 / Math.Cos(60 * pi / 180) * dxc);
            Vector2 v3 = fun.Polar(p0, 90 * pi / 180, ic / 2 / Math.Cos(60 * pi / 180) * dxc);

            Vector2 p25 = fun.Polar(p9, -2 * pi / 3, l1);
            Vector2 p26 = fun.Polar(p9, -pi / 6, l1);


            Vector2 p27 = fun.Polar(p0, 0.5 * pi, ic * 1.1);
            Vector2 p28 = fun.Polar(p0, -0.5 * pi, ic / 2 * 1.5);

            Vector2 zx1 = fun.Polar(p0, pi / 2, 50);
            Vector2 zx2 = fun.Polar(p0, pi / -2, 50);


            Line line20 = new Line(p25, p9);
            line20.Lineweight = Lineweight.W25;
            line20.Layer = additionalline;
            dxf.AddEntity(line20);



            Vector2 p29 = fun.mirrorpoint(p25, zx1, zx2);

            Line line21 = new Line(p29, p25);
            line21.Lineweight = Lineweight.W25;
            line21.Layer = contour;
            dxf.AddEntity(line21);

            LwPolyline poly1 = new LwPolyline();
            poly1.Vertexes.Add(new LwPolylineVertex(p29));
            poly1.Vertexes.Add(new LwPolylineVertex(p25));
            poly1.Vertexes.Add(new LwPolylineVertex(p9));
            poly1.Vertexes.Add(new LwPolylineVertex(p8));
            poly1.Vertexes[2].Bulge = -Math.Tan((pi - epsr) / 4);
            poly1.Vertexes.Add(new LwPolylineVertex(p29));

            //            poly1.SetConstantWidth(0.05);
            poly1.IsClosed = true;
            fun.PolyFill(dxf, poly1, 0.4, contour);

            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            Arc[] harc1 = new Arc[100];
            int hnumst1 = poly1.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = poly1.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)poly1.Explode()[i];
                }
                if (htype1[i] == "Arc")
                {
                    harc1[i] = (Arc)poly1.Explode()[i];
                }
            }
            fun.hatchsub1(dxf, htype1, hnumst1, 45, 1, hline1, harc1, hatching);


            if (cb == 1 || cb == 2)
            {


                Line line15 = new Line(v1, v2);
                line15.Lineweight = Lineweight.W25;
                line15.Layer = additionalline;
                dxf.AddEntity(line15);
                Line line16 = new Line(v2, v3);
                line16.Lineweight = Lineweight.W25;
                line16.Layer = additionalline;
                dxf.AddEntity(line16);
                Line line17 = new Line(v1, v3);
                line17.Lineweight = Lineweight.W25;
                line17.Layer = additionalline;
                dxf.AddEntity(line17);

            }



            insert.inserthole(dxf, p0, v2, v3, p20, p21, scale, data);

            Arc arc3 = fun.DrawArc(p8, p3p, p9);

            LwPolyline poly11 = new LwPolyline();
            poly11.Vertexes.Add(new LwPolylineVertex(p4));
            poly11.Vertexes[0].Bulge = Math.Tan((pi - epsr) / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p5));
            poly11.Vertexes.Add(new LwPolylineVertex(p6));
            poly11.Vertexes[2].Bulge = Math.Tan((pi - epsr) / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p7));
            poly11.Vertexes.Add(new LwPolylineVertex(p8));
            poly11.Vertexes[4].Bulge = Math.Tan((pi - epsr) / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p9));
            poly11.IsClosed = true;
            fun.PolyFill(dxf, poly11, 0.5, contour);
            Line line12 = new Line(p1, p2);
            line12.Lineweight = Lineweight.W25;
            line12.Layer = additionalline;
            dxf.AddEntity(line12);
            Line line13 = new Line(p2, p3);
            line13.Lineweight = Lineweight.W25;
            line13.Layer = additionalline;
            dxf.AddEntity(line13);
            Line line14 = new Line(p1, p3);
            line14.Lineweight = Lineweight.W25;
            line14.Layer = additionalline;
            dxf.AddEntity(line14);

            Line cenline1 = new Line(fun.Polar(p0, pi, ic / 2 + 2), fun.Polar(p0, 0, ic / 2 + 2));
            Line cenline2 = new Line(fun.Polar(p0, 0.5 * pi, ic + 2), fun.Polar(p0, -0.5 * pi, ic / 2 + 2));
            Line cenline3 = new Line(fun.Polar(p20, 0, 2), fun.Polar(p20, pi, s + 2));
            Circle dotcircle1 = new Circle(p0, ic / 2);
            cenline1.Layer = center;
            cenline2.Layer = center;
            cenline3.Layer = center;
            dotcircle1.Layer = refin;
            cenline1.Linetype = Linetype.Center;
            cenline2.Linetype = Linetype.Center;
            cenline3.Linetype = Linetype.Center;
            dotcircle1.Linetype = Linetype.DashDot;
            dxf.AddEntity(cenline1);
            dxf.AddEntity(cenline2);
            dxf.AddEntity(cenline3);
            dxf.AddEntity(dotcircle1);


            DimensionStyle dimensionStyle = new DimensionStyle("sd");
            dimensionStyle.ArrowSize = textsize;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            dimensionStyle.TextHeight = textsize;
            //标注
            if (DIM == 0)
            {
                LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi, ic / 2), fun.Polar(p0, 0, ic / 2)), offset + ic / 2, 180, dimensionStyle);
                dim1.UserText = "IC";
                dxf.AddEntity(dim1);

                LinearDimension dim2 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                dim2.UserText = "S";
                dxf.AddEntity(dim2);



                if (re / scale != 0.001)
                {
                    RadialDimension dimrad1 = new RadialDimension(arc3, 10, offset, dimensionStyle);//DimensionStyle.Default);
                    dimrad1.UserText = "RE";
                    dxf.AddEntity(dimrad1);
                }

                LinearDimension dim4 = new LinearDimension(new Line(p1, p2), offset * 2, 180, dimensionStyle);
                dim4.UserText = "LE";
                dxf.AddEntity(dim4);

                if (an != 0)
                {
                    Pus.NeedleDim(dxf, new Line(p23, fun.Polar(p23, pi - an * pi / 180, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, "AN", dimensionStyle);
                }
            }
            else
            {
                if (ictc == 0)
                {
                    LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi, ic / 2), fun.Polar(p0, 0, ic / 2)), offset + ic / 2, 180, dimensionStyle);
                    dim1.UserText = String.Format("IC={0}", ic / scale);
                    dxf.AddEntity(dim1);
                }
                if (ictc != 0)
                {
                    LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi, ic / 2), fun.Polar(p0, 0, ic / 2)), offset + ic / 2, 180, dimensionStyle);
                    dim1.UserText = String.Format("IC={0}±{1}", ic / scale, ictc);
                    dxf.AddEntity(dim1);
                }
                if (stc == 0)
                {
                    LinearDimension dim2 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                    dim2.UserText = String.Format("S={0}", s / scale);
                    dxf.AddEntity(dim2);
                }
                LinearDimension dim5 = new LinearDimension(new Line(p1, p2), offset * 2, 180, dimensionStyle);
                dim5.UserText = String.Format("LE={0}", Math.Round(le, 2));
                dxf.AddEntity(dim5);
            }
            if (stc != 0)
            {
                LinearDimension dim2 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                dim2.UserText = String.Format("S={0}±{1}", s / scale, stc);
                dxf.AddEntity(dim2);
            }


            if (re / scale != 0.001)
            {
                RadialDimension dimrad1 = new RadialDimension(arc3, 10, offset, dimensionStyle);//DimensionStyle.Default);
                dimrad1.UserText = String.Format("RE={0}", re / scale);
                dxf.AddEntity(dimrad1);
            }



            if (an != 0)
            {
                //Pus.NeedleDim(dxf, new Line(p23, fun.Polar(p23, pi - an*pi/180, 1)), new Line(p24, fun.Polar(p24, pi, 1)),  offset*1.5, "AN=" + an  + "°", dimensionStyle);
                fun.jdbz2(dxf, new Line(p24, p23), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, 1.2, 1.6, 0.9, "AN=" + an + "°", "", "");

            }



            fun.dimrot1(dxf, p8, p25, 60, offset, 2, 1.2, 1.6, 0.9, "l1", "", "");

            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - offset * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }
            fun.SetLayer(dxf);
            fun.SetByLayer(dxf);

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2018;
            dxf.Save(path);



        }

        public static void _RhombicInsert(Dictionary<string, Object> data)    //镶边等边四边形刀片，适用于S,C,D,E,F,M,V型刀片 图1-4
        {
            DxfDocument dxf = new DxfDocument();

            Layer contour = new Layer("contour");//轮廓层
            Layer dimensioning = new Layer("dimensioning");//尺寸层
            Layer refin = new Layer("refin");//基准线/内轮廓/虚线
            Layer center = new Layer("center");//中心线
            Layer textlayer = new Layer("textlayer");//文本层
            Layer hatching = new Layer("hatching");//填充层
            Layer additionalline = new Layer("additionalline");//附加线
            Layer cutting = new Layer("cutting");//切削层
            fun.SetLayer(dxf);

            double offset = 10;
            double textsize = 3.5;

            double scale = Convert.ToDouble(data["scale"]); //放大系数
            double tic = Convert.ToDouble(data["ic"]);

            if (scale == 0 && tic < 9)
            {
                scale = 3.0;
            }
            else if (scale == 0 && tic < 20)
            {
                scale = 2.5;
            }
            else if (scale == 0)
            {
                scale = 2.0;
            }
            double Lw = 1.0;  //轮廓线线宽
                              //double Lw1 = 0;  

            //if(Convert.ToDouble(data["isweb"])==0)  //网页展示的线宽
            //{
            //    Lw = 1.0;
            //}
            //if(Convert.ToDouble(data["isweb"]) == 1)  //下载的标准线宽
            //{
            //    Lw = 0.5;
            //}

            double pi = Math.PI;
            double DIM = Convert.ToDouble(data["dim"]) * scale;
            double ic = Convert.ToDouble(data["ic"]) * scale;
            double s = Convert.ToDouble(data["s"]) * scale;
            double d1 = Convert.ToDouble(data["d1"]) * scale;
            double re = Convert.ToDouble(data["re"]) * scale;
            int cb = (int)Convert.ToDecimal(data["cb"]);
            double epsr = Convert.ToDouble(data["epsr"]) * pi / 180;
            double an = Convert.ToDouble(data["an"]);
            int ifs = (int)Convert.ToDecimal(data["ifs"]);
            double le = (ic / (Math.Cos(pi / 2 - epsr)));
            double isframe = Convert.ToDouble(data["isframe"]);
            string path = Convert.ToString(data["path"]);
            double dxc = Convert.ToDouble(data["dxc"]);
            double ictc = Convert.ToDouble(data["ictc"]) * scale;
            double stc = Convert.ToDouble(data["stc"]) * scale;
            double d1tc = 0;
            double l1 = Convert.ToDouble(data["l1"]) * scale;

            /*
            double pi = Math.PI;
            double DIM = 1;
            double ic = 9.525;
            double s =4.76;
            double d1 = 3.81;
            double re = 1.2;
            int cb = 0;
            double epsr = 55 * pi/180;
            double an =0;
            int ifs = 2;
            double le = (ic / (Math.Cos(pi / 2 - epsr)));
            double isframe = 0;
            string path = Convert.ToString(data["path"]);
            double dxc = 0.8;
            double ictc = 0;
            double stc = 0;
            double d1tc = 0;
            double l1 =0.8;
            */



            Vector2 p1 = new Vector2(0, 0);
            Vector2 p0 = fun.Polar(p1, epsr / 2, (ic / 2) / Math.Sin(epsr / 2));
            Vector2 p2 = fun.Polar(p1, 0, le);
            Vector2 p3 = fun.Polar(p2, epsr, le);
            Vector2 p4 = fun.Polar(p1, epsr, le);
            Vector2 p1p = fun.Polar(p1, epsr / 2, re / Math.Sin(epsr / 2));
            Vector2 p5 = new Vector2(p1p.X - re * (Math.Cos(pi / 2 - epsr)), p1p.Y + re * Math.Sin(pi / 2 - epsr));
            Vector2 p6 = new Vector2(p1p.X, p1p.Y - re);
            Vector2 p2p = fun.Polar(p2, (pi + epsr) / 2, re / Math.Sin((pi - epsr) / 2));
            Vector2 p7 = new Vector2(p2p.X, p2p.Y - re);
            Vector2 p8 = new Vector2(p2p.X + re * Math.Cos(pi / 2 - epsr), p2p.Y - re * Math.Sin(pi / 2 - epsr));
            Vector2 p3p = fun.Polar(p3, pi + epsr / 2, re / Math.Sin(epsr / 2));
            Vector2 p9 = new Vector2(p3p.X + re * Math.Cos(pi / 2 - epsr), p3p.Y - re * Math.Sin(pi / 2 - epsr));
            Vector2 p10 = new Vector2(p3p.X, p3p.Y + re);
            Vector2 p4p = fun.Polar(p4, -((pi - epsr) / 2), re / Math.Sin((pi - epsr) / 2));
            Vector2 p11 = new Vector2(p4p.X, p4p.Y + re);
            Vector2 p12 = fun.Polar(p4p, (pi / 2 + epsr), re);
            Vector2 p20 = fun.Polar(p0, 0, (ic * 4));
            Vector2 p21 = fun.Polar(p20, (pi / 2), (ic / 2));
            Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
            Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
            Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));

            Vector2 p25 = new Vector2(p6.X + l1, p6.Y);
            Vector2 p26 = fun.Polar(p5, epsr, l1);


            Vector2 v1 = fun.Polar(p0, 180 * pi / 180 + epsr / 2, (ic / 2) / Math.Cos(epsr / 2) * dxc);
            Vector2 v2 = fun.Polar(p0, -90 * pi / 180 + epsr / 2, (ic / 2) / Math.Cos(epsr / 2) * dxc);
            Vector2 v3 = fun.Polar(p0, epsr / 2, (ic / 2) / Math.Cos(epsr / 2) * dxc);
            Vector2 v4 = fun.Polar(p0, 90 * pi / 180 + epsr / 2, (ic / 2) / Math.Cos(epsr / 2) * dxc);





            if (cb == 1 || cb == 2)
            {

                LwPolyline Line01 = new LwPolyline();
                Line01.Vertexes.Add(new LwPolylineVertex(v1));
                Line01.Vertexes.Add(new LwPolylineVertex(v2));
                Line01.Vertexes.Add(new LwPolylineVertex(v3));
                Line01.Vertexes.Add(new LwPolylineVertex(v4));
                Line01.Vertexes.Add(new LwPolylineVertex(v1));
                Line01.Lineweight = Lineweight.W35;
                Line01.Layer = additionalline;
                dxf.AddEntity(Line01);

            }


            Arc arc = fun.DrawArc(p5, p1p, p6);
            Circle circle1 = new Circle(p0, (d1 / 2.0));

            LwPolyline poly11 = new LwPolyline();
            poly11.Vertexes.Add(new LwPolylineVertex(p5));
            poly11.Vertexes[0].Bulge = Math.Tan((pi - epsr) / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p6));
            poly11.Vertexes.Add(new LwPolylineVertex(p7));
            poly11.Vertexes[2].Bulge = Math.Tan(epsr / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p8));
            poly11.Vertexes.Add(new LwPolylineVertex(p9));
            poly11.Vertexes[4].Bulge = Math.Tan((pi - epsr) / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p10));
            poly11.Vertexes.Add(new LwPolylineVertex(p11));
            poly11.Vertexes[6].Bulge = Math.Tan(epsr / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p12));
            poly11.Vertexes.Add(new LwPolylineVertex(p5));
            fun.PolyFill(dxf, poly11, 0.5, contour);

            LwPolyline line00 = new LwPolyline();
            line00.Vertexes.Add(new LwPolylineVertex(p1));
            line00.Vertexes.Add(new LwPolylineVertex(p2));
            line00.Vertexes.Add(new LwPolylineVertex(p3));
            line00.Vertexes.Add(new LwPolylineVertex(p4));
            line00.Vertexes.Add(new LwPolylineVertex(p1));
            line00.Lineweight = Lineweight.W25;
            line00.Layer = additionalline;
            dxf.AddEntity(line00);



            Vector2[] Line21 = { p25, p26 };
            fun.drawBLine(dxf, Line21, 0.5, contour);

            Circle circle3 = new Circle(p0, (ic / 2.0));
            circle3.Linetype = Linetype.DashDot;
            circle3.Layer = refin;
            dxf.AddEntity(circle3);


            /* if (epsr == 35 * pi / 180)
            {
                inserthole(dxf, p0, v2, v3, fun.Polar(p20, 0, 2 * s), fun.Polar(p21, 0, 2 * s), scale, data);
                Line cenline3 = new Line(fun.Polar(fun.Polar(p20, 0, 2 * s), 0, 3), fun.Polar(fun.Polar(p20, 0, 2 * s), pi, s + 3));
                cenline3.Layer = center;
                cenline3.Linetype = Linetype.Center;
                dxf.AddEntity(cenline3);
            }
            else
            {
                inserthole(dxf, p0, v2, v3, p20, p21, scale, data);
                Line cenline3 = new Line(fun.Polar(p20, 0, 3), fun.Polar(p20, pi, s + 3));
                cenline3.Layer = center;
                cenline3.Linetype = Linetype.Center;
                dxf.AddEntity(cenline3);
            }
            */
            Line cenline1 = new Line(fun.Polar(p0, pi, (ic / 2) + 2), fun.Polar(p0, 0, (ic / 2) + 2));
            Line cenline2 = new Line(fun.Polar(p0, pi / 2, (ic / 2) + 2), fun.Polar(p0, -pi / 2, (ic / 2) + 2));

            cenline1.Layer = center;
            cenline2.Layer = center;

            cenline1.Linetype = Linetype.Center;
            cenline2.Linetype = Linetype.Center;
            dxf.AddEntity(cenline1);
            dxf.AddEntity(cenline2);

            insert.inserthole(dxf, p0, v2, v3, p20, p21, scale, data);

            LwPolyline poly1 = new LwPolyline();
            poly1.Vertexes.Add(new LwPolylineVertex(p25));
            poly1.Vertexes.Add(new LwPolylineVertex(p6));
            poly1.Vertexes.Add(new LwPolylineVertex(p5));

            poly1.Vertexes[1].Bulge = -Math.Tan((pi - epsr) / 4);
            poly1.Vertexes.Add(new LwPolylineVertex(p26));
            poly1.Vertexes.Add(new LwPolylineVertex(p25));

            //            poly1.SetConstantWidth(0.05);
            poly1.IsClosed = true;
            fun.PolyFill(dxf, poly1, 0.4, contour);

            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            Arc[] harc1 = new Arc[100];
            int hnumst1 = poly1.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = poly1.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)poly1.Explode()[i];
                }
                if (htype1[i] == "Arc")
                {
                    harc1[i] = (Arc)poly1.Explode()[i];
                }
            }
            fun.hatchsub1(dxf, htype1, hnumst1, 45, 1, hline1, harc1, hatching);

            DimensionStyle ds = new DimensionStyle("ds");
            ds.ArrowSize = textsize;
            ds.DimArrow1 = DimensionArrowhead.Closedfilled;
            ds.DimArrow2 = DimensionArrowhead.Closedfilled;
            ds.TextHeight = textsize;
            //标注
            if (DIM == 0)
            {
                if (epsr == 35 * pi / 180)
                {
                    LinearDimension dimX1 = new LinearDimension(new Line(fun.Polar(p23, 0, 2 * s), fun.Polar(p24, 0, 2 * s)), offset, 180, ds);
                    dimX1.UserText = "S";
                    dxf.AddEntity(dimX1);
                }
                else
                {
                    LinearDimension dimX1 = new LinearDimension(new Line(p23, p24), offset, 180, ds);
                    dimX1.UserText = "S";
                    dxf.AddEntity(dimX1);
                }



                LinearDimension dimX2 = new LinearDimension(new Line(p4, new Vector2(p4.X, p1.Y)), offset + p4.X, 90, ds);
                dimX2.UserText = "IC";
                dxf.AddEntity(dimX2);

                LinearDimension dimX3 = new LinearDimension(new Line(new Vector2(p20.X - s, p20.Y + d1 / 2), new Vector2(p20.X - s, p20.Y - d1 / 2)), offset, 90, ds);

                if (re / scale != 0.001)
                {
                    RadialDimension dimrad1 = new RadialDimension(arc, 225, offset, ds);//DimensionStyle.Default);
                    dimrad1.UserText = "RE";
                    dxf.AddEntity(dimrad1);
                }

                Angular2LineDimension dimang1 = new Angular2LineDimension(new Line(p3, fun.Polar(p3, epsr, 0.1)), new Line(p3, fun.Polar(p3, 0, 0.1)), offset * 2, ds);
                dimang1.UserText = "EPSR";
                dxf.AddEntity(dimang1);

                if (an != 0)
                {
                    Pus.NeedleDim(dxf, new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, "AN", ds);
                }
            }
            else
            {
                if (ictc == 0)
                {
                    LinearDimension dim1 = new LinearDimension(new Line(p4, new Vector2(p4.X, p1.Y)), offset + p4.X, 90, ds);
                    dim1.UserText = String.Format("IC={0}", ic / scale);
                    dxf.AddEntity(dim1);
                }
                if (ictc != 0)
                {
                    LinearDimension dim1 = new LinearDimension(new Line(p4, new Vector2(p4.X, p1.Y)), offset + p4.X, 90, ds);
                    dim1.UserText = String.Format("IC={0}±{1}", ic / scale, ictc);
                    dxf.AddEntity(dim1);
                }


                if (stc == 0)
                {
                    if (epsr == 35 * pi / 180)
                    {
                        LinearDimension dimX1 = new LinearDimension(new Line(fun.Polar(p23, 0, 2 * s), fun.Polar(p24, 0, 2 * s)), offset, 180, ds);
                        dimX1.UserText = String.Format("S={0}", s / scale);
                        dxf.AddEntity(dimX1);
                    }
                    else
                    {
                        LinearDimension dimX1 = new LinearDimension(new Line(p23, p24), offset, 180, ds);
                        dimX1.UserText = "S";
                        dxf.AddEntity(dimX1);
                    }


                }
                if (stc != 0)
                {
                    if (epsr == 35 * pi / 180)
                    {
                        LinearDimension dim2 = new LinearDimension(new Line(fun.Polar(p23, 0, 2 * s), fun.Polar(p24, 0, 2 * s)), offset, 180, ds);
                        dim2.UserText = String.Format("S={0}±{1}", s / scale, stc);
                        dxf.AddEntity(dim2);
                    }
                    else
                    {
                        LinearDimension dim2 = new LinearDimension(new Line(p23, p24), offset, 180, ds);
                        dim2.UserText = String.Format("S={0}±{1}", s / scale, stc);
                        dxf.AddEntity(dim2);
                    }
                }


                LinearDimension dimX3 = new LinearDimension(new Line(new Vector2(p20.X - s, p20.Y + d1 / 2), new Vector2(p20.X - s, p20.Y - d1 / 2)), offset, 90, ds);

                if (re / scale != 0.001)
                {
                    RadialDimension dimrad1 = new RadialDimension(arc, 225, offset, ds);//DimensionStyle.Default);
                    dimrad1.UserText = String.Format("RE={0}", re / scale);
                    dxf.AddEntity(dimrad1);
                }

                Angular2LineDimension dimang1 = new Angular2LineDimension(new Line(p3, fun.Polar(p3, epsr, 0.1)), new Line(p3, fun.Polar(p3, 0, 0.1)), offset * 2, ds);
                dimang1.UserText = String.Format("EPSR={0}°", epsr * 180 / pi);
                dxf.AddEntity(dimang1);

                if (an != 0)
                {
                    Pus.NeedleDim(dxf, new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, "AN=" + an * 180 / pi + "°", ds);
                }
            }

            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 90, p0.Y + 120), data);
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }


            LinearDimension dimX5 = new LinearDimension(new Line(p1, p25), offset * 1.5, 90, ds);
            dimX5.UserText = "l1";
            dxf.AddEntity(dimX5);


            fun.SetLayer(dxf);
            fun.SetByLayer(dxf);


            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2018;
            dxf.Save(path);

        }

        public static void _Rhombicclass13(Dictionary<string, Object> data)    //带固定孔的正方形铣削刀片
        {
            DxfDocument dxf = new DxfDocument();

            Layer contour = new Layer("contour");//轮廓层
            Layer dimensioning = new Layer("dimensioning");//尺寸层
            Layer refin = new Layer("refin");//基准线/内轮廓/虚线
            Layer center = new Layer("center");//中心线
            Layer textlayer = new Layer("textlayer");//文本层
            Layer hatching = new Layer("hatching");//填充层
            Layer additionalline = new Layer("additionalline");//附加线
            Layer cutting = new Layer("cutting");//切削层
            fun.SetLayer(dxf);

            double offset = 10;
            double textsize = 3.5;

            double tic = Convert.ToDouble(data["ic"]); ;
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0 && tic < 9)
            {
                scale = 3.0;
            }
            else if (scale == 0 && tic < 20)
            {
                scale = 2.5;
            }
            else if (scale == 0)
            {
                scale = 2.0;
            }
            double Lw = 1.0;  //轮廓线线宽
                              //double Lw1 = 0;  

            //if(Convert.ToDouble(data["isweb"])==0)  //网页展示的线宽
            //{
            //    Lw = 1.0;
            //}
            //if(Convert.ToDouble(data["isweb"]) == 1)  //下载的标准线宽
            //{
            //    Lw = 0.5;
            //}

            double pi = Math.PI;
            double DIM = Convert.ToDouble(data["dim"]);
            double s = Convert.ToDouble(data["s"]) * scale;
            double d1 = Convert.ToDouble(data["d1"]) * scale;
            double re = Convert.ToDouble(data["re"]) * scale;
            int cb = (int)Convert.ToDecimal(data["cb"]);
            double epsr = Convert.ToDouble(data["epsr"]) * pi / 180;
            double an = Convert.ToDouble(data["an"]);
            int ifs = (int)Convert.ToDecimal(data["ifs"]);
            double l = Convert.ToDouble(data["l"]) * scale;
            double isframe = Convert.ToDouble(data["isframe"]) * scale;
            string path = Convert.ToString(data["path"]);
            double dxc = Convert.ToDouble(data["dxc"]);
            double ictc = Convert.ToDouble(data["ictc"]);
            double stc = Convert.ToDouble(data["stc"]);
            double d1tc = 0;
            double l1 = Convert.ToDouble(data["l1"]) * scale;
            double d = Convert.ToDouble(data["ic"]) * scale;
            double ic = d;
            double le = (ic / (Math.Cos(pi / 2 - epsr)));

            /*
            double pi = Math.PI;
            double DIM = 1;
         
            double s =4.76* scale;
            double d1 = 3.81* scale;
            double re = 1.2* scale;
            int cb = 0;
            double epsr = 90 * pi/180;
            double an =11;
            int ifs = 2;
           
            double isframe = 0* scale;
            string path = Convert.ToString(data["path"]);
            double dxc = 0.8;
            double ictc = 0* scale;
            double stc = 0* scale;
            double d1tc = 0;
            double l1 =0.8* scale;
            double d = 9.525* scale;
            double ic = d;
            double le = (ic / (Math.Cos(pi / 2 - epsr)));
            */
            Vector2 p1 = new Vector2(0, 0);
            Vector2 p0 = fun.Polar(p1, epsr / 2, (ic / 2) / Math.Sin(epsr / 2));
            Vector2 p2 = fun.Polar(p1, 0, le);
            Vector2 p3 = fun.Polar(p2, epsr, le);
            Vector2 p4 = fun.Polar(p1, epsr, le);
            Vector2 p1p = fun.Polar(p1, epsr / 2, re / Math.Sin(epsr / 2));
            Vector2 p5 = new Vector2(p1p.X - re * (Math.Cos(pi / 2 - epsr)), p1p.Y + re * Math.Sin(pi / 2 - epsr));
            Vector2 p6 = new Vector2(p1p.X, p1p.Y - re);
            Vector2 p2p = fun.Polar(p2, (pi + epsr) / 2, re / Math.Sin((pi - epsr) / 2));
            Vector2 p7 = new Vector2(p2p.X, p2p.Y - re);
            Vector2 p8 = new Vector2(p2p.X + re * Math.Cos(pi / 2 - epsr), p2p.Y - re * Math.Sin(pi / 2 - epsr));
            Vector2 p3p = fun.Polar(p3, pi + epsr / 2, re / Math.Sin(epsr / 2));
            Vector2 p9 = new Vector2(p3p.X + re * Math.Cos(pi / 2 - epsr), p3p.Y - re * Math.Sin(pi / 2 - epsr));
            Vector2 p10 = new Vector2(p3p.X, p3p.Y + re);
            Vector2 p4p = fun.Polar(p4, -((pi - epsr) / 2), re / Math.Sin((pi - epsr) / 2));
            Vector2 p11 = new Vector2(p4p.X, p4p.Y + re);
            Vector2 p12 = fun.Polar(p4p, (pi / 2 + epsr), re);
            Vector2 p20 = fun.Polar(p0, 0, (ic * 4));
            Vector2 p21 = fun.Polar(p20, (pi / 2), (ic / 2));
            Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an * pi / 180)));
            Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
            Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an * pi / 180)));

            Vector2 p25 = new Vector2(p6.X + l1, p6.Y);
            Vector2 p26 = fun.Polar(p5, epsr, l1);


            Vector2 v1 = fun.Polar(p0, 180 * pi / 180 + epsr / 2, (ic / 2) / Math.Sin(epsr / 2) * dxc);
            Vector2 v2 = fun.Polar(p0, -90 * pi / 180 + epsr / 2, (ic / 2) / Math.Cos(epsr / 2) * dxc);
            Vector2 v3 = fun.Polar(p0, epsr / 2, (ic / 2) / Math.Sin(epsr / 2) * dxc);
            Vector2 v4 = fun.Polar(p0, 90 * pi / 180 + epsr / 2, (ic / 2) / Math.Cos(epsr / 2) * dxc);





            if (cb == 1 || cb == 2)
            {

                LwPolyline Line01 = new LwPolyline();
                Line01.Vertexes.Add(new LwPolylineVertex(v1));
                Line01.Vertexes.Add(new LwPolylineVertex(v2));
                Line01.Vertexes.Add(new LwPolylineVertex(v3));
                Line01.Vertexes.Add(new LwPolylineVertex(v4));
                Line01.Vertexes.Add(new LwPolylineVertex(v1));
                Line01.Lineweight = Lineweight.W35;
                Line01.Layer = additionalline;
                dxf.AddEntity(Line01);

            }


            Arc arc = fun.DrawArc(p5, p1p, p6);
            //Circle circle1 = new Circle(p0 , (d1 / 2.0));

            LwPolyline poly11 = new LwPolyline();
            poly11.Vertexes.Add(new LwPolylineVertex(p5));
            poly11.Vertexes[0].Bulge = Math.Tan((pi - epsr) / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p6));
            poly11.Vertexes.Add(new LwPolylineVertex(p7));
            poly11.Vertexes[2].Bulge = Math.Tan(epsr / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p8));
            poly11.Vertexes.Add(new LwPolylineVertex(p9));
            poly11.Vertexes[4].Bulge = Math.Tan((pi - epsr) / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p10));
            poly11.Vertexes.Add(new LwPolylineVertex(p11));
            poly11.Vertexes[6].Bulge = Math.Tan(epsr / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p12));
            poly11.Vertexes.Add(new LwPolylineVertex(p5));
            fun.PolyFill(dxf, poly11, 0.5, contour);

            LwPolyline line00 = new LwPolyline();
            line00.Vertexes.Add(new LwPolylineVertex(p1));
            line00.Vertexes.Add(new LwPolylineVertex(p2));
            line00.Vertexes.Add(new LwPolylineVertex(p3));
            line00.Vertexes.Add(new LwPolylineVertex(p4));
            line00.Vertexes.Add(new LwPolylineVertex(p1));
            line00.Lineweight = Lineweight.W25;
            line00.Layer = additionalline;
            dxf.AddEntity(line00);



            Vector2[] Line21 = { p25, p26 };
            fun.drawBLine(dxf, Line21, 0.5, contour);

            Circle circle3 = new Circle(p0, (ic / 2.0));
            circle3.Linetype = Linetype.DashDot;
            circle3.Layer = refin;
            dxf.AddEntity(circle3);


            /* if (epsr == 35 * pi / 180)
            {
                inserthole(dxf, p0, v2, v3, fun.Polar(p20, 0, 2 * s), fun.Polar(p21, 0, 2 * s), scale, data);
                Line cenline3 = new Line(fun.Polar(fun.Polar(p20, 0, 2 * s), 0, 3), fun.Polar(fun.Polar(p20, 0, 2 * s), pi, s + 3));
                cenline3.Layer = center;
                cenline3.Linetype = Linetype.Center;
                dxf.AddEntity(cenline3);
            }
            else
            {
                inserthole(dxf, p0, v2, v3, p20, p21, scale, data);
                Line cenline3 = new Line(fun.Polar(p20, 0, 3), fun.Polar(p20, pi, s + 3));
                cenline3.Layer = center;
                cenline3.Linetype = Linetype.Center;
                dxf.AddEntity(cenline3);
            }
            */
            Line cenline1 = new Line(fun.Polar(p0, pi, (ic / 2) * 1.5), fun.Polar(p0, 0, (ic / 2) * 1.5));
            Line cenline2 = new Line(fun.Polar(p0, pi / 2, (ic / 2) * 1.5), fun.Polar(p0, -pi / 2, (ic / 2) * 1.5));

            cenline1.Layer = center;
            cenline2.Layer = center;

            cenline1.Linetype = Linetype.Center;
            cenline2.Linetype = Linetype.Center;
            dxf.AddEntity(cenline1);
            dxf.AddEntity(cenline2);

            insert.inserthole(dxf, p0, v2, v3, p20, p21, scale, data);

            LwPolyline poly1 = new LwPolyline();
            poly1.Vertexes.Add(new LwPolylineVertex(p25));
            poly1.Vertexes.Add(new LwPolylineVertex(p6));
            poly1.Vertexes.Add(new LwPolylineVertex(p5));

            poly1.Vertexes[1].Bulge = -Math.Tan((pi - epsr) / 4);
            poly1.Vertexes.Add(new LwPolylineVertex(p26));
            poly1.Vertexes.Add(new LwPolylineVertex(p25));

            //            poly1.SetConstantWidth(0.05);
            poly1.IsClosed = true;
            fun.PolyFill(dxf, poly1, 0.4, contour);

            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            Arc[] harc1 = new Arc[100];
            int hnumst1 = poly1.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = poly1.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)poly1.Explode()[i];
                }
                if (htype1[i] == "Arc")
                {
                    harc1[i] = (Arc)poly1.Explode()[i];
                }
            }
            fun.hatchsub1(dxf, htype1, hnumst1, 45, 1, hline1, harc1, hatching);

            DimensionStyle ds = fun.DimStyle(true);
            DimensionStyle ds2 = fun.DimStyle(false);

            //标注
            if (DIM == 0)
            {
                if (epsr == 35 * pi / 180)
                {
                    LinearDimension dimX1 = new LinearDimension(new Line(fun.Polar(p23, 0, 2 * s), fun.Polar(p24, 0, 2 * s)), offset, 180, ds);
                    dimX1.UserText = "S";
                    dxf.AddEntity(dimX1);
                }
                else
                {
                    LinearDimension dimX1 = new LinearDimension(new Line(p23, p24), offset, 180, ds);
                    dimX1.UserText = "S";
                    dxf.AddEntity(dimX1);
                }



                LinearDimension dimX2 = new LinearDimension(new Line(p1, p4), offset, 90, ds);
                dimX2.UserText = "d=l";
                dxf.AddEntity(dimX2);

                LinearDimension dimX3 = new LinearDimension(new Line(new Vector2(p20.X - s, p20.Y + d1 / 2), new Vector2(p20.X - s, p20.Y - d1 / 2)), offset, 90, ds);

                if (re / scale != 0.001)
                {
                    RadialDimension dimrad1 = new RadialDimension(arc, 225, offset, ds);//DimensionStyle.Default);
                    dimrad1.UserText = "RE";
                    dxf.AddEntity(dimrad1);
                }

                Angular2LineDimension dimang1 = new Angular2LineDimension(new Line(p3, fun.Polar(p3, epsr, 0.1)), new Line(p3, fun.Polar(p3, 0, 0.1)), offset, ds);
                dimang1.UserText = "EPSR";
                dxf.AddEntity(dimang1);

                if (an != 0)
                {
                    Angular3PointDimension dimang2 = new Angular3PointDimension(p24, p23, new Vector2(p24.X - 1, p24.Y), offset * 3 + s, ds2);
                    dimang2.UserText = String.Format("AN={0}°", an);
                    dxf.AddEntity(dimang2);
                }
            }

            else
            {
                if (ictc == 0)
                {
                    LinearDimension dim1 = new LinearDimension(new Line(p1, p4), offset, 90, ds);
                    dim1.UserText = String.Format("d={0}", ic / scale);
                    dxf.AddEntity(dim1);
                }
                if (ictc != 0)
                {
                    LinearDimension dim1 = new LinearDimension(new Line(p1, p4), offset, 90, ds);
                    dim1.UserText = String.Format("d={0}±{1}", ic / scale, ictc);
                    dxf.AddEntity(dim1);
                }


                if (stc == 0)
                {
                    if (epsr == 35 * pi / 180)
                    {
                        LinearDimension dimX1 = new LinearDimension(new Line(fun.Polar(p23, 0, 2 * s), fun.Polar(p24, 0, 2 * s)), offset, 180, ds);
                        dimX1.UserText = String.Format("S={0}", s / scale);
                        dxf.AddEntity(dimX1);
                    }
                    else
                    {
                        LinearDimension dimX1 = new LinearDimension(new Line(p23, p24), offset, 180, ds);
                        dimX1.UserText = "S";
                        dxf.AddEntity(dimX1);
                    }


                }
                if (stc != 0)
                {
                    if (epsr == 35 * pi / 180)
                    {
                        LinearDimension dim2 = new LinearDimension(new Line(fun.Polar(p23, 0, 2 * s), fun.Polar(p24, 0, 2 * s)), offset, 180, ds);
                        dim2.UserText = String.Format("S={0}±{1}", s / scale, stc);
                        dxf.AddEntity(dim2);
                    }
                    else
                    {
                        LinearDimension dim2 = new LinearDimension(new Line(p23, p24), offset, 180, ds);
                        dim2.UserText = String.Format("S={0}±{1}", s / scale, stc);
                        dxf.AddEntity(dim2);
                    }
                }


                LinearDimension dimX3 = new LinearDimension(new Line(new Vector2(p20.X - s, p20.Y + d1 / 2), new Vector2(p20.X - s, p20.Y - d1 / 2)), offset, 90, ds);

                if (re / scale != 0.001)
                {
                    RadialDimension dimrad1 = new RadialDimension(arc, 225, offset, ds);//DimensionStyle.Default);
                    dimrad1.UserText = String.Format("RE={0}", re / scale);
                    dxf.AddEntity(dimrad1);
                }

                Angular2LineDimension dimang1 = new Angular2LineDimension(new Line(p3, fun.Polar(p3, epsr, 0.1)), new Line(p3, fun.Polar(p3, 0, 0.1)), offset, ds);
                dimang1.UserText = String.Format("EPSR={0}°", epsr * 180 / pi);
                dxf.AddEntity(dimang1);

                if (an != 0)
                {
                    Angular3PointDimension dimang2 = new Angular3PointDimension(p24, p23, new Vector2(p24.X - 1, p24.Y), offset * 3 + s, ds2);
                    dimang2.UserText = String.Format("AN={0}°", an);
                    dxf.AddEntity(dimang2);
                }
            }

            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 90, p0.Y + 120), data);
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }


            LinearDimension dimX5 = new LinearDimension(new Line(p1, p25), offset, 180, ds2);
            dimX5.UserText = "l1";
            dxf.AddEntity(dimX5);


            fun.SetLayer(dxf);
            fun.SetByLayer(dxf);


            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2018;
            dxf.Save(path);


        }

        public static void _Rhombicclass12(Dictionary<string, Object> data)    //带固定孔的正方形铣削刀片
        {
            DxfDocument dxf = new DxfDocument();

            Layer contour = new Layer("contour");//轮廓层
            Layer dimensioning = new Layer("dimensioning");//尺寸层
            Layer refin = new Layer("refin");//基准线/内轮廓/虚线
            Layer center = new Layer("center");//中心线
            Layer textlayer = new Layer("textlayer");//文本层
            Layer hatching = new Layer("hatching");//填充层
            Layer additionalline = new Layer("additionalline");//附加线
            Layer cutting = new Layer("cutting");//切削层
            fun.SetLayer(dxf);

            double offset = 10;
            double textsize = 3.5;


            double tic = 0;
            double scale = 1; //放大系数
            if (scale == 0 && tic < 9)
            {
                scale = 3.0;
            }
            else if (scale == 0 && tic < 20)
            {
                scale = 2.5;
            }
            else if (scale == 0)
            {
                scale = 2.0;
            }
            double Lw = 1.0;  //轮廓线线宽
                              //double Lw1 = 0;  

            //if(Convert.ToDouble(data["isweb"])==0)  //网页展示的线宽
            //{
            //    Lw = 1.0;
            //}
            //if(Convert.ToDouble(data["isweb"]) == 1)  //下载的标准线宽
            //{
            //    Lw = 0.5;
            //}

            double pi = Math.PI;
            double DIM = Convert.ToDouble(data["dim"]) * scale;
            double ic = Convert.ToDouble(data["ic"]) * scale;
            double s = Convert.ToDouble(data["s"]) * scale;
            double d1 = Convert.ToDouble(data["d1"]) * scale;
            double re = Convert.ToDouble(data["re"]) * scale;
            int cb = (int)Convert.ToDecimal(data["cb"]);
            double epsr = Convert.ToDouble(data["eqsr"]) * pi / 180 * scale;
            double an = Convert.ToDouble(data["an"]) * scale;
            int ifs = (int)Convert.ToDecimal(data["ifs"]);
            double le = (ic / (Math.Cos(pi / 2 - epsr)));
            double isframe = Convert.ToDouble(data["isframe"]) * scale;
            string path = Convert.ToString(data["path"]);
            double dxc = Convert.ToDouble(data["dxc"]) * scale;
            double ictc = Convert.ToDouble(data["ictc"]) * scale;
            double stc = Convert.ToDouble(data["stc"]) * scale;
            double d1tc = 0;
            double m = Convert.ToDouble(data["M"]) * scale;
            double l1 = Convert.ToDouble(data["l1"]) * scale;
            double kch = Convert.ToDouble(data["kch"]) * pi / 180 * scale;
            double krins = Convert.ToDouble(data["krins"]) * pi / 180 * scale;
            double bs = Convert.ToDouble(data["bs"]) * scale;
            double bch = Convert.ToDouble(data["bch"]) * scale;



            /*
            double pi = Math.PI;
            double DIM = 1;
            double ic = 9.525;
            double s = 3.97;
            double d1 =4.4;
            double re = 1.2;
            int cb = 0;
            double epsr =90*pi/180;
            double an = 0;
            int ifs = 2;
            double le = (ic / (Math.Cos(pi / 2 - epsr)));
            double isframe =0;
            string path = Convert.ToString(data["path"]);
            double dxc = 0.8;
            double ictc = 0;
            double stc = 0;
            double d1tc = 0;
            double m = 0.543;
            double l1 = 3.0;
            double kch = 37.5*pi/180;
            double krins = 75*pi/180;
            double bs =1.124;
            double bch = 1.4;
            */
            Vector2 p1 = new Vector2(0, 0);

            Vector2 p2 = fun.Polar(p1, pi - (epsr - krins), ic);
            Vector2 p3 = fun.Polar(p2, krins, ic);
            Vector2 p4 = fun.Polar(p3, -(epsr - krins), ic);

            Vector2 p1p = fun.Polar(p1, epsr / 3, re / Math.Sin(epsr / 2));
            Vector2 p2p = fun.Polar(p2, (pi + epsr) / 2, re / Math.Sin((pi - epsr) / 2));
            Vector2 p3p = fun.Polar(p3, pi + epsr / 2, re / Math.Sin(epsr / 2));
            Vector2 p4p = fun.Polar(p4, -((pi - epsr) / 2), re / Math.Sin((pi - epsr) / 2));

            Vector2 p5 = fun.Polar(p2, -(epsr - krins), re);
            Vector2 p6 = fun.Polar(p2, krins, re);
            Vector2 p7 = fun.Polar(p3, -(pi - krins), re);
            Vector2 p8 = fun.Polar(p3, -(epsr - krins), re);

            Vector2 p9 = fun.Polar(p4, pi - (epsr - krins), re);
            Vector2 p10 = fun.Polar(p4, -(pi - krins), re);


            Vector2 p11 = fun.Polar(p4, -(pi - krins), ic - l1);
            Vector2 p12 = fun.Polar(p1, krins, re);
            Vector2 p13 = fun.Polar(p12, -(pi - kch), bs);
            Vector2 p14 = fun.Polar(p13, -pi, bch);
            Vector2 p15 = fun.Polar(p1, pi - (epsr - krins), l1);

            Vector2 p0 = fun.Polar(p2, pi / 6, (ic / 2) / Math.Sin(epsr / 2));

            //标注点
            Vector2 p16 = fun.Polar(p13, 145, l1);
            Vector2 p17 = new Vector2(p1.X + l1, p1.Y);
            Vector2 p18 = fun.Polar(p1, pi - (epsr - krins), ic / 2);
            Vector2 p19 = new Vector2(p14.X + l1, p14.Y);


            Line cenline1 = new Line(fun.Polar(p0, krins, (ic / 2) * 1.5), fun.Polar(p0, -105 * pi / 180, (ic / 2) * 1.5));
            Line cenline2 = new Line(fun.Polar(p0, pi - (epsr - krins), (ic / 2) * 1.5), fun.Polar(p0, -15 * pi / 180, (ic / 2) * 1.5));

            cenline1.Layer = center;
            cenline2.Layer = center;

            cenline1.Linetype = Linetype.Center;
            cenline2.Linetype = Linetype.Center;
            dxf.AddEntity(cenline1);
            dxf.AddEntity(cenline2);



            Vector2 p20 = fun.Polar(p0, 0, (ic * 2));
            Vector2 p21 = fun.Polar(p20, (pi / 2), (ic / 2));
            Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
            Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
            Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));

            Vector2 p25 = fun.Inters(p14, new Vector2(p14.X + l1, p14.Y), p12, fun.Polar(p12, -105 * pi / 180, l1));


            Vector2 v1 = fun.Polar(p2, pi / 6, (ic / 2) / Math.Sin(epsr / 2) * dxc);
            Vector2 v2 = fun.Polar(p3, -pi / 6, (ic / 2) / Math.Cos(epsr / 2) * dxc);
            Vector2 v3 = fun.Polar(p4, epsr / 2, (ic / 2) / Math.Sin(epsr / 2) * dxc);
            Vector2 v4 = fun.Polar(p0, 90 * pi / 180 + epsr / 2, (ic / 2) / Math.Cos(epsr / 2) * dxc);


            Vector2[] Line21 = { p11, p15 };
            fun.drawBLine(dxf, Line21, 0.5, contour);

            Line line16 = new Line(p16, p12);
            dxf.AddEntity(line16);


            if (cb == 1 || cb == 2)
            {

                LwPolyline Line01 = new LwPolyline();
                Line01.Vertexes.Add(new LwPolylineVertex(v1));
                Line01.Vertexes.Add(new LwPolylineVertex(v2));
                Line01.Vertexes.Add(new LwPolylineVertex(v3));
                Line01.Vertexes.Add(new LwPolylineVertex(v4));
                Line01.Vertexes.Add(new LwPolylineVertex(v1));
                Line01.Lineweight = Lineweight.W35;
                Line01.Layer = additionalline;
                dxf.AddEntity(Line01);

            }


            Arc arc = fun.DrawArc(p5, p1p, p6);
            Circle circle1 = new Circle(p0, (d1 / 2.0));

            LwPolyline poly11 = new LwPolyline();
            poly11.Vertexes.Add(new LwPolylineVertex(p6));
            poly11.Vertexes.Add(new LwPolylineVertex(p5));
            poly11.Vertexes[0].Bulge = Math.Tan((pi - epsr) / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p14));
            poly11.Vertexes.Add(new LwPolylineVertex(p13));
            poly11.Vertexes.Add(new LwPolylineVertex(p12));
            poly11.Vertexes.Add(new LwPolylineVertex(p11));
            poly11.Vertexes.Add(new LwPolylineVertex(p10));
            poly11.Vertexes.Add(new LwPolylineVertex(p9));
            poly11.Vertexes[6].Bulge = Math.Tan((pi - epsr) / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p8));
            poly11.Vertexes.Add(new LwPolylineVertex(p7));
            poly11.Vertexes[8].Bulge = Math.Tan((pi - epsr) / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p6));


            fun.PolyFill(dxf, poly11, 0.5, contour);


            LwPolyline line00 = new LwPolyline();
            line00.Vertexes.Add(new LwPolylineVertex(p1));
            line00.Vertexes.Add(new LwPolylineVertex(p2));
            line00.Vertexes.Add(new LwPolylineVertex(p3));
            line00.Vertexes.Add(new LwPolylineVertex(p4));
            line00.Vertexes.Add(new LwPolylineVertex(p1));
            line00.Lineweight = Lineweight.W25;
            line00.Layer = additionalline;
            dxf.AddEntity(line00);


            LwPolyline Arc00 = new LwPolyline();
            Arc00.Vertexes.Add(new LwPolylineVertex(p14));
            Arc00.Vertexes.Add(new LwPolylineVertex(p12));
            Arc00.Vertexes[0].Bulge = Math.Tan((pi - epsr) / 4);
            Arc00.Lineweight = Lineweight.W50;
            Arc00.Layer = contour;
            fun.PolyFill(dxf, Arc00, 0.5, contour);


            Circle circle3 = new Circle(p0, (ic / 2.0));
            circle3.Linetype = Linetype.DashDot;
            circle3.Layer = refin;
            dxf.AddEntity(circle3);


            /* if (epsr == 35 * pi / 180)
            {
                inserthole(dxf, p0, v2, v3, fun.Polar(p20, 0, 2 * s), fun.Polar(p21, 0, 2 * s), scale, data);
                Line cenline3 = new Line(fun.Polar(fun.Polar(p20, 0, 2 * s), 0, 3), fun.Polar(fun.Polar(p20, 0, 2 * s), pi, s + 3));
                cenline3.Layer = center;
                cenline3.Linetype = Linetype.Center;
                dxf.AddEntity(cenline3);
            }
            else
            {
                inserthole(dxf, p0, v2, v3, p20, p21, scale, data);
                Line cenline3 = new Line(fun.Polar(p20, 0, 3), fun.Polar(p20, pi, s + 3));
                cenline3.Layer = center;
                cenline3.Linetype = Linetype.Center;
                dxf.AddEntity(cenline3);
            }

            Line cenline1 = new Line(fun.Polar(p0, pi, (ic / 2) * 1.5), fun.Polar(p0, 0, (ic / 2) * 1.5));
            Line cenline2 = new Line(fun.Polar(p0, pi / 2, (ic / 2) * 1.5), fun.Polar(p0, -pi / 2, (ic / 2) * 1.5));

            cenline1.Layer = center;
            cenline2.Layer = center;

            cenline1.Linetype = Linetype.Center;
            cenline2.Linetype = Linetype.Center;
            dxf.AddEntity(cenline1);
            dxf.AddEntity(cenline2);
            */
            //insert .inserthole(dxf, p0, v2, v3, p20, p21, scale, data);
            LwPolyline poly1 = new LwPolyline();
            poly1.Vertexes.Add(new LwPolylineVertex(p11));
            poly1.Vertexes.Add(new LwPolylineVertex(p12));
            poly1.Vertexes.Add(new LwPolylineVertex(p13));
            poly1.Vertexes.Add(new LwPolylineVertex(p14));
            poly1.Vertexes.Add(new LwPolylineVertex(p15));
            poly1.Vertexes.Add(new LwPolylineVertex(p11));
            //            poly1.SetConstantWidth(0.05);
            poly1.IsClosed = true;
            fun.PolyFill(dxf, poly1, 0.4, contour);

            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            Arc[] harc1 = new Arc[100];
            int hnumst1 = poly1.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = poly1.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)poly1.Explode()[i];
                }
                if (htype1[i] == "Arc")
                {
                    harc1[i] = (Arc)poly1.Explode()[i];
                }
            }
            fun.hatchsub1(dxf, htype1, hnumst1, 45, 1, hline1, harc1, hatching);


            DimensionStyle ds = new DimensionStyle("ds");
            ds.ArrowSize = textsize;
            ds.DimArrow1 = DimensionArrowhead.Closedfilled;
            ds.DimArrow2 = DimensionArrowhead.Closedfilled;
            ds.TextHeight = textsize;
            ds.ExtLineExtend = 0.2;
            //标注
            if (DIM == 0)
            {
                if (epsr == 35 * pi / 180)
                {
                    LinearDimension dimX1 = new LinearDimension(new Line(fun.Polar(p23, 0, 2 * s), fun.Polar(p24, 0, 2 * s)), offset, 180, ds);
                    dimX1.UserText = "S";
                    dxf.AddEntity(dimX1);
                }
                else
                {
                    LinearDimension dimX1 = new LinearDimension(new Line(p23, p24), offset, 180, ds);
                    dimX1.UserText = "S";
                    dxf.AddEntity(dimX1);
                }





                // LinearDimension dimX3 = new LinearDimension(new Line(new Vector2(p20.X - s, p20.Y + d1 / 2), new Vector2(p20.X - s, p20.Y - d1 / 2)), offset, 90, ds);




                if (an != 0)
                {
                    Pus.NeedleDim(dxf, new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, "AN", ds);
                }
            }


            if (stc == 0)
            {
                if (epsr == 35 * pi / 180)
                {
                    LinearDimension dimX1 = new LinearDimension(new Line(fun.Polar(p23, 0, 2 * s), fun.Polar(p24, 0, 2 * s)), offset * 3, 180, ds);
                    dimX1.UserText = String.Format("S={0}", s / scale);
                    dxf.AddEntity(dimX1);
                }
                else
                {
                    LinearDimension dimX1 = new LinearDimension(new Line(p23, p24), offset * 3, 180, ds);
                    dimX1.UserText = "S";
                    dxf.AddEntity(dimX1);
                }


            }
            if (stc != 0)
            {
                if (epsr == 35 * pi / 180)
                {
                    LinearDimension dim2 = new LinearDimension(new Line(fun.Polar(p23, 0, 2 * s), fun.Polar(p24, 0, 2 * s)), offset * 3, 180, ds);
                    dim2.UserText = String.Format("S={0}±{1}", s / scale, stc);
                    dxf.AddEntity(dim2);
                }
                else
                {
                    LinearDimension dim2 = new LinearDimension(new Line(p23, p24), offset * 3, 180, ds);
                    dim2.UserText = String.Format("S={0}±{1}", s / scale, stc);
                    dxf.AddEntity(dim2);
                }
            }


            LinearDimension dimX3 = new LinearDimension(new Line(new Vector2(p20.X - s, p20.Y + d1 / 2), new Vector2(p20.X - s, p20.Y - d1 / 2)), offset, 90, ds);



            if (an != 0)
            {
                Pus.NeedleDim(dxf, new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, "AN=" + an * 180 / pi + "°", ds);
            }


            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 90, p0.Y + 120), data);
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }

            LinearDimension dimX2 = new LinearDimension(new Line(p2, p3), offset, 75, ds);
            dimX2.UserText = "d=l";
            dxf.AddEntity(dimX2);
            LinearDimension dimX5 = new LinearDimension(new Line(p11, p1), offset, -115, ds);
            dimX5.UserText = "l1";
            dxf.AddEntity(dimX5);

            LinearDimension dimX6 = new LinearDimension(new Line(p18, p14), offset + 5, 90, ds);
            dimX6.UserText = "m";
            dxf.AddEntity(dimX6);
            LinearDimension dimX7 = new LinearDimension(new Line(p13, p14), offset + 3, 180, ds);
            dimX7.UserText = "1.4";
            dxf.AddEntity(dimX7);

            LinearDimension dimX8 = new LinearDimension(new Line(p13, p12), offset + 5, 220, ds);
            dimX8.UserText = "1.124";
            dxf.AddEntity(dimX8);

            fun.jdbz1(dxf, new Line(p12, p11), new Line(p12, p16), offset + 5, "37.5°", 0.5);


            fun.jdbz1(dxf, new Line(p25, p4), new Line(p25, p19), offset + 5, "75°", 0.5);

            fun.SetLayer(dxf);
            fun.SetByLayer(dxf);

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2018;
            dxf.Save(path);



        }

        public static void _Rhombic80class12(Dictionary<string, Object> data)    //带固定孔的80 菱形铣削刀片
        {
            DxfDocument dxf = new DxfDocument();

            Layer contour = new Layer("contour");//轮廓层
            Layer dimensioning = new Layer("dimensioning");//尺寸层
            Layer refin = new Layer("refin");//基准线/内轮廓/虚线
            Layer center = new Layer("center");//中心线
            Layer textlayer = new Layer("textlayer");//文本层
            Layer hatching = new Layer("hatching");//填充层
            Layer additionalline = new Layer("additionalline");//附加线
            Layer cutting = new Layer("cutting");//切削层
            fun.SetLayer(dxf);

            double offset = 10;
            double textsize = 3.5;

            double tic = 0;
            double scale = 1; //放大系数
            if (scale == 0 && tic < 9)
            {
                scale = 3.0;
            }
            else if (scale == 0 && tic < 20)
            {
                scale = 2.5;
            }
            else if (scale == 0)
            {
                scale = 2.0;
            }
            double Lw = 1.0;  //轮廓线线宽
                              //double Lw1 = 0;  

            //if(Convert.ToDouble(data["isweb"])==0)  //网页展示的线宽
            //{
            //    Lw = 1.0;
            //}
            //if(Convert.ToDouble(data["isweb"]) == 1)  //下载的标准线宽
            //{
            //    Lw = 0.5;
            //}

            double pi = Math.PI;
            double DIM = Convert.ToDouble(data["dim"]) * scale;
            double ic = Convert.ToDouble(data["ic"]) * scale;
            double s = Convert.ToDouble(data["s"]) * scale;
            double d1 = Convert.ToDouble(data["d1"]) * scale;
            double re = Convert.ToDouble(data["dc"]) * scale;
            int cb = (int)Convert.ToDecimal(data["cb"]);
            double epsr = Convert.ToDouble(data["epsr"]) * pi / 180 * scale;
            double an = Convert.ToDouble(data["an"]) * scale;
            int ifs = (int)Convert.ToDecimal(data["ifs"]);
            double le = (ic / (Math.Cos(pi / 2 - epsr)));
            double isframe = Convert.ToDouble(data["isframe"]) * scale;
            string path = Convert.ToString(data["path"]);
            double dxc = Convert.ToDouble(data["dxc"]) * scale;
            double ictc = Convert.ToDouble(data["ictc"]) * scale;
            double stc = Convert.ToDouble(data["stc"]) * scale;
            double d1tc = 0;
            double m = 0.631;
            double l1 = Convert.ToDouble(data["l1"]) * scale;
            double kch = Convert.ToDouble(data["kch"]) * pi / 180 * scale;
            double krins = Convert.ToDouble(data["krins"]) * pi / 180 * scale;
            double bs = Convert.ToDouble(data["bs"]) * scale;
            double bch = Convert.ToDouble(data["bch"]) * scale;
            double l = Convert.ToDouble(data["l"]) * scale;
            /*
           double pi = Math.PI;
            double DIM = 1;
            double ic =9.525;
            double s = 3.97;
            double d1 = 4.4;
            double re = 1.2;
            int cb = 0;
            double epsr = 80*pi/180;
            double an = 7;
            int ifs = 2;
            double le = (ic / (Math.Cos(pi / 2 - epsr)));
            double isframe = 0;
            string path = Convert.ToString(data["path"]);
            double dxc = 0.8;
            double ictc = 0;
            double stc = 0;
            double d1tc = 0;
            double m = 0.631;
            double l1 = 3;
            double kch = 45*pi/180;
            double krins = 90*pi/180;
            double bs = 0.2;
            double bch = 1.4;
            double l = 9.67;
          */

            Vector2 p1 = new Vector2(0, 0);

            Vector2 p2 = fun.Polar(p1, pi - (krins - epsr), l);
            Vector2 p3 = fun.Polar(p2, krins, l);
            Vector2 p4 = fun.Polar(p3, -(krins - epsr), l);

            Vector2 p1p = fun.Polar(p1, epsr / 3, re / Math.Sin(epsr / 2));
            Vector2 p2p = fun.Polar(p2, (pi + epsr) / 2, re / Math.Sin((pi - epsr) / 2));
            Vector2 p3p = fun.Polar(p3, pi + epsr / 2, re / Math.Sin(epsr / 2));
            Vector2 p4p = fun.Polar(p4, -((pi - epsr) / 2), re / Math.Sin((pi - epsr) / 2));

            Vector2 p5 = fun.Polar(p1, pi - (krins - epsr), bs);
            Vector2 p6 = fun.Polar(p5, pi - (krins - epsr), bch);
            Vector2 p7 = fun.Polar(p1, pi - (krins - epsr), l1);
            Vector2 p8 = fun.Polar(p2, -(krins - epsr), re);

            Vector2 p9 = fun.Polar(p2, pi / 2, re);
            Vector2 p10 = fun.Polar(p3, -pi / 2, re);


            Vector2 p11 = fun.Polar(p3, -(krins - epsr), re);
            Vector2 p12 = fun.Polar(p4, pi - (krins - epsr), re);
            Vector2 p13 = fun.Polar(p4, -pi / 2, re);
            Vector2 p14 = fun.Polar(p4, -pi / 2, l - l1);
            Vector2 p15 = fun.Polar(p1, pi / 2, bs * Math.Tan(kch));


            Vector2 p0 = fun.Polar(p2, epsr / 2, (ic / 2) / Math.Sin(epsr * 180 / pi / 2));










            //标注点
            Vector2 p16 = fun.Polar(p0, -pi / 2, ic / 2);
            Vector2 p17 = new Vector2(p1.X + l1, p1.Y);
            Vector2 p18 = fun.Polar(p1, pi - (epsr - krins), ic / 2);
            Vector2 p19 = new Vector2(p14.X + l1, p14.Y);


            Vector2 p20 = fun.Polar(p0, 0, (ic * 2));
            Vector2 p21 = fun.Polar(p20, (pi / 2), (ic / 2));
            Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
            Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
            Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));

            Vector2 p25 = fun.Inters(p5, new Vector2(p5.X + l1, p5.Y), p15, new Vector2(p15.X, p15.Y - l1));

            Vector2 p26 = new Vector2(p5.X + l1, p5.Y);

            Vector2 v1 = fun.Polar(p2, pi / 2, (ic / 2) * dxc);
            Vector2 v2 = fun.Polar(p0, pi / 2, (ic / 2) * dxc);
            Vector2 v3 = fun.Polar(p0, pi / -2, (ic / 2) * dxc);
            Vector2 v4 = fun.Polar(p0, 0, (ic / 2) * dxc);




            Line line16 = new Line(p14, p7);
            dxf.AddEntity(line16);


            if (cb == 1 || cb == 2)
            {

                LwPolyline Line01 = new LwPolyline();
                Line01.Vertexes.Add(new LwPolylineVertex(v1));
                Line01.Vertexes.Add(new LwPolylineVertex(v2));
                Line01.Vertexes.Add(new LwPolylineVertex(v3));
                Line01.Vertexes.Add(new LwPolylineVertex(v4));
                Line01.Vertexes.Add(new LwPolylineVertex(v1));
                Line01.Lineweight = Lineweight.W35;
                Line01.Layer = additionalline;
                dxf.AddEntity(Line01);

            }


            Arc arc = fun.DrawArc(p5, p1p, p6);
            Circle circle1 = new Circle(p0, (d1 / 2.0));

            LwPolyline poly11 = new LwPolyline();
            poly11.Vertexes.Add(new LwPolylineVertex(p8));
            poly11.Vertexes.Add(new LwPolylineVertex(p9));
            poly11.Vertexes[0].Bulge = -Math.Tan((pi - epsr) / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p10));
            poly11.Vertexes.Add(new LwPolylineVertex(p11));
            poly11.Vertexes[2].Bulge = -Math.Tan((pi - epsr) / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p12));
            poly11.Vertexes.Add(new LwPolylineVertex(p13));
            poly11.Vertexes[4].Bulge = -Math.Tan((pi - epsr) / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p15));
            poly11.Vertexes.Add(new LwPolylineVertex(p5));
            poly11.Vertexes.Add(new LwPolylineVertex(p6));
            poly11.Vertexes.Add(new LwPolylineVertex(p7));
            poly11.Vertexes.Add(new LwPolylineVertex(p8));


            fun.PolyFill(dxf, poly11, 0.5, contour);


            LwPolyline line00 = new LwPolyline();
            line00.Vertexes.Add(new LwPolylineVertex(p1));
            line00.Vertexes.Add(new LwPolylineVertex(p2));
            line00.Vertexes.Add(new LwPolylineVertex(p3));
            line00.Vertexes.Add(new LwPolylineVertex(p4));
            line00.Vertexes.Add(new LwPolylineVertex(p1));
            line00.Lineweight = Lineweight.W25;
            line00.Layer = additionalline;
            dxf.AddEntity(line00);

            // insert.inserthole(dxf, p0, v2, v3, p20, p21, scale, data);

            /* LwPolyline Arc00 = new LwPolyline();
             Arc00.Vertexes.Add(new LwPolylineVertex(p14));
             Arc00.Vertexes.Add(new LwPolylineVertex(p12));
             Arc00.Vertexes[0].Bulge = Math.Tan((pi - epsr) / 4);
             Arc00.Lineweight = Lineweight.W50;
             Arc00.Layer = contour;
             fun.PolyFill(dxf, Arc00, 0.5, contour);
            */

            Circle circle3 = new Circle(p0, (ic / 2.0));
            circle3.Linetype = Linetype.DashDot;
            circle3.Layer = refin;
            dxf.AddEntity(circle3);

            /*
            if (epsr == 35 * pi / 180)
            {
                insert . inserthole(dxf, p0, v2, v3, fun.Polar(p20, 0, 2 * s), fun.Polar(p21, 0, 2 * s), scale, data);
                Line cenline3 = new Line(fun.Polar(fun.Polar(p20, 0, 2 * s), 0, 3), fun.Polar(fun.Polar(p20, 0, 2 * s), pi, s + 3));
                cenline3.Layer = center;
                cenline3.Linetype = Linetype.Center;
                dxf.AddEntity(cenline3);
            }
            else
            {
                insert .inserthole(dxf, p0, v2, v3, p20, p21, scale, data);
                Line cenline3 = new Line(fun.Polar(p20, 0, 3), fun.Polar(p20, pi, s + 3));
                cenline3.Layer = center;
                cenline3.Linetype = Linetype.Center;
                dxf.AddEntity(cenline3);
            }
            */
            insert.inserthole(dxf, p0, v2, v3, p20, p21, scale, data);
            Line cenline1 = new Line(fun.Polar(p0, pi, (ic / 2) * 1.5), fun.Polar(p0, 0, (ic / 2) * 1.5));
            Line cenline2 = new Line(fun.Polar(p0, pi / 2, (ic / 2) * 1.5), fun.Polar(p0, -pi / 2, (ic / 2) * 1.5));

            cenline1.Layer = center;
            cenline2.Layer = center;

            cenline1.Linetype = Linetype.Center;
            cenline2.Linetype = Linetype.Center;
            dxf.AddEntity(cenline1);
            dxf.AddEntity(cenline2);


            /*
            LwPolyline poly1 = new LwPolyline();
            poly1.Vertexes.Add(new LwPolylineVertex(p14));
            poly1.Vertexes.Add(new LwPolylineVertex(p15));
            poly1.Vertexes.Add(new LwPolylineVertex(p5));
            poly1.Vertexes.Add(new LwPolylineVertex(p6));
            poly1.Vertexes.Add(new LwPolylineVertex(p7));
            poly1.Vertexes.Add(new LwPolylineVertex(p14));
            //            poly1.SetConstantWidth(0.05);
            poly1.IsClosed = true;
            fun.PolyFill(dxf, poly1, 0.4, contour);

            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            Arc[] harc1 = new Arc[100];
            int hnumst1 = poly1.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = poly1.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)poly1.Explode()[i];
                }
                if (htype1[i] == "Arc")
                {
                    harc1[i] = (Arc)poly1.Explode()[i];
                }
            }
            fun.hatchsub1(dxf, htype1, hnumst1, 45, 1, hline1, harc1, hatching);
            */

            DimensionStyle ds = new DimensionStyle("ds");
            ds.ArrowSize = textsize;
            ds.DimArrow1 = DimensionArrowhead.Closedfilled;
            ds.DimArrow2 = DimensionArrowhead.Closedfilled;
            ds.TextHeight = textsize;
            ds.ExtLineExtend = 0.2;

            //标注
            if (DIM == 0)
            {
                if (epsr == 35 * pi / 180)
                {
                    LinearDimension dimX1 = new LinearDimension(new Line(fun.Polar(p23, 0, 2 * s), fun.Polar(p24, 0, 2 * s)), offset, 180, ds);
                    dimX1.UserText = "S";
                    dxf.AddEntity(dimX1);
                }
                else
                {
                    LinearDimension dimX1 = new LinearDimension(new Line(p23, p24), offset, 180, ds);
                    dimX1.UserText = "S";
                    dxf.AddEntity(dimX1);
                }





                // LinearDimension dimX3 = new LinearDimension(new Line(new Vector2(p20.X - s, p20.Y + d1 / 2), new Vector2(p20.X - s, p20.Y - d1 / 2)), offset, 90, ds);




                if (an != 0)
                {
                    Pus.NeedleDim(dxf, new Line(p23, fun.Polar(p23, pi - an * pi / 180, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, "AN", ds);
                }

            }


            if (stc == 0)
            {
                if (epsr == 35 * pi / 180)
                {
                    LinearDimension dimX1 = new LinearDimension(new Line(fun.Polar(p23, 0, 2 * s), fun.Polar(p24, 0, 2 * s)), offset * 3, 180, ds);
                    dimX1.UserText = String.Format("S={0}", s / scale);
                    dxf.AddEntity(dimX1);
                }
                else
                {
                    LinearDimension dimX1 = new LinearDimension(new Line(p23, p24), offset * 3, 180, ds);
                    dimX1.UserText = "S";
                    dxf.AddEntity(dimX1);
                }


            }
            if (stc != 0)
            {
                if (epsr == 35 * pi / 180)
                {
                    LinearDimension dim2 = new LinearDimension(new Line(fun.Polar(p23, 0, 2 * s), fun.Polar(p24, 0, 2 * s)), offset * 3, 180, ds);
                    dim2.UserText = String.Format("S={0}±{1}", s / scale, stc);
                    dxf.AddEntity(dim2);
                }
                else
                {
                    LinearDimension dim2 = new LinearDimension(new Line(p23, p24), offset * 3, 180, ds);
                    dim2.UserText = String.Format("S={0}±{1}", s / scale, stc);
                    dxf.AddEntity(dim2);
                }
            }


            LinearDimension dimX3 = new LinearDimension(new Line(new Vector2(p20.X - s, p20.Y + d1 / 2), new Vector2(p20.X - s, p20.Y - d1 / 2)), offset * 2, 90, ds);


            /*
            if (an != 0)
            {
                Pus.NeedleDim(dxf, new Line(p23, fun.Polar(p23, pi - an*pi/180, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset*2, "AN=" + an  + "°", ds);
            }
            */


            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 90, p0.Y + 120), data);
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }

            LinearDimension dimX2 = new LinearDimension(new Line(p2, p3), offset * 2, 90, ds);
            dimX2.UserText = "l";
            dxf.AddEntity(dimX2);
            LinearDimension dimX5 = new LinearDimension(new Line(p14, p5), offset * 2, 270, ds);
            dimX5.UserText = "l1";
            dxf.AddEntity(dimX5);

            LinearDimension dimX6 = new LinearDimension(new Line(p6, p16), offset + 5, 90, ds);
            dimX6.UserText = "m";
            dxf.AddEntity(dimX6);
            LinearDimension dimX7 = new LinearDimension(new Line(p5, p6), offset + 3, 180, ds);
            dimX7.UserText = "1.4";
            dxf.AddEntity(dimX7);

            LinearDimension dimX8 = new LinearDimension(new Line(p15, p5), offset + 5, 180, ds);
            dimX8.UserText = "0.2";
            dxf.AddEntity(dimX8);
            LinearDimension dimX9 = new LinearDimension(new Line(p3, p4), offset * 3, 360, ds);
            dimX9.UserText = "d";
            dxf.AddEntity(dimX9);
            fun.jdbz1(dxf, new Line(p5, p26), new Line(p5, p15), offset * 2 + 5, "45°", 0.5);


            fun.jdbz1(dxf, new Line(p25, p13), new Line(p25, p26), offset * 2 + 5, "90°", 0.5);

            fun.SetLayer(dxf);
            fun.SetByLayer(dxf);

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2018;
            dxf.Save(path);


        }

        public static void _Rhombic21951p8(Dictionary<string, Object> data)    //21951图8不带固定孔的80。菱形(c)，圆形(R)，正方形(s)和三角形(T)刀片，车削刀片
        {
            DxfDocument dxf = new DxfDocument();

            Layer contour = new Layer("contour");//轮廓层
            Layer dimensioning = new Layer("dimensioning");//尺寸层
            Layer refin = new Layer("refin");//基准线/内轮廓/虚线
            Layer center = new Layer("center");//中心线
            Layer textlayer = new Layer("textlayer");//文本层
            Layer hatching = new Layer("hatching");//填充层
            Layer additionalline = new Layer("additionalline");//附加线
            Layer cutting = new Layer("cutting");//切削层
            fun.SetLayer(dxf);

            double offset = 10;
            double textsize = 3.5;

            double tic = Convert.ToDouble(data["ic"]); ;
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0 && tic < 9)
            {
                scale = 3.0;
            }
            else if (scale == 0 && tic < 20)
            {
                scale = 2.5;
            }
            else if (scale == 0)
            {
                scale = 2.0;
            }
            double Lw = 1.0;  //轮廓线线宽
                              //double Lw1 = 0;  

            //if(Convert.ToDouble(data["isweb"])==0)  //网页展示的线宽
            //{
            //    Lw = 1.0;
            //}
            //if(Convert.ToDouble(data["isweb"]) == 1)  //下载的标准线宽
            //{
            //    Lw = 0.5; 
            //}
            double pi = Math.PI;
            double m1 = Convert.ToDouble(data["m1"]) * scale;
            double m2 = Convert.ToDouble(data["m2"]) * scale;
            double dim = Convert.ToDouble(data["dim"]) * scale;
            double ic = Convert.ToDouble(data["ic"]) * scale;
            double s = Convert.ToDouble(data["s"]) * scale;
            double d1 = Convert.ToDouble(data["d1"]) * scale;
            double re = Convert.ToDouble(data["re"]) * scale;
            int cb = (int)Convert.ToDecimal(data["cb"]);
            double epsr = Convert.ToDouble(data["epsr"]) * pi / 180;
            double an = Convert.ToDouble(data["an"]);
            int ifs = (int)Convert.ToDecimal(data["ifs"]);
            double le = (ic / (Math.Cos(pi / 2 - epsr)));
            double isframe = Convert.ToDouble(data["isframe"]);
            string path = Convert.ToString(data["path"]);
            double dxc = Convert.ToDouble(data["dxc"]) * scale;
            double ictc = Convert.ToDouble(data["ictc"]) * scale; ;
            double stc = Convert.ToDouble(data["stc"]) * scale;
            double d1tc = 0;

            /*
            double m1 = 2.426;
            double m2 = 1.333;
                        double pi = Math.PI;
                        string path = Convert.ToString(data["path"]);
                        double dim = 1;
                        double ic = 9.525;
                        double s = 4.76;
                        double d1 = 3.81;
                        double re = 1.2;
                        int cb = (int)0;
                        double epsr = 80*pi /180;
                        double an = 7;
                        int ifs = 2;
                        double le = (ic / (Math.Cos(pi / 2 - epsr)));
                        double isframe = 0;
                        double dxc = 0.8;
                        double ictc = 0;
                        double stc = 0;
                        double d1tc = 0;
            */




            Vector2 p1 = new Vector2(0, 0);
            Vector2 p0 = fun.Polar(p1, epsr / 2, (ic / 2) / Math.Sin(epsr / 2));
            Vector2 p2 = fun.Polar(p1, 0, le);
            Vector2 p3 = fun.Polar(p2, epsr, le);
            Vector2 p4 = fun.Polar(p1, epsr, le);
            Vector2 p1p = fun.Polar(p1, epsr / 2, re / Math.Sin(epsr / 2));
            Vector2 p5 = new Vector2(p1p.X - re * (Math.Cos(pi / 2 - epsr)), p1p.Y + re * Math.Sin(pi / 2 - epsr));
            Vector2 p6 = new Vector2(p1p.X, p1p.Y - re);
            Vector2 p2p = fun.Polar(p2, (pi + epsr) / 2, re / Math.Sin((pi - epsr) / 2));
            Vector2 p7 = new Vector2(p2p.X, p2p.Y - re);
            Vector2 p8 = new Vector2(p2p.X + re * Math.Cos(pi / 2 - epsr), p2p.Y - re * Math.Sin(pi / 2 - epsr));
            Vector2 p3p = fun.Polar(p3, pi + epsr / 2, re / Math.Sin(epsr / 2));
            Vector2 p9 = new Vector2(p3p.X + re * Math.Cos(pi / 2 - epsr), p3p.Y - re * Math.Sin(pi / 2 - epsr));
            Vector2 p10 = new Vector2(p3p.X, p3p.Y + re);
            Vector2 p4p = fun.Polar(p4, -((pi - epsr) / 2), re / Math.Sin((pi - epsr) / 2));
            Vector2 p11 = new Vector2(p4p.X, p4p.Y + re);
            Vector2 p12 = fun.Polar(p4p, (pi / 2 + epsr), re);
            Vector2 p20 = fun.Polar(p0, 0, (ic * 2));
            Vector2 p21 = fun.Polar(p20, (pi / 2), (ic / 2));
            Vector2 p22 = new Vector2(p21.X - s, p21.Y - (s * Math.Tan(an)));
            Vector2 p24 = fun.Polar(p20, (-pi / 2), (ic / 2));
            //Vector2 p23 = new Vector2(p24.X - s, p24.Y + (s * Math.Tan(an)));
            Vector2 p23 = new Vector2(p24.X - s, p24.Y);
            Vector2 p25 = new Vector2(p0.X, p0.Y + ic / 2);
            Vector2 p26 = new Vector2(p0.X, p0.Y - ic / 2);
            Vector2 p27 = fun.Polar(p0, 130 * pi / 180, ic / 2);
            Vector2 p28 = fun.Polar(p4p, 130 * pi / 180, re);
            Vector2 p29 = fun.Polar(p0, 235 * pi / 180, ic / 2);
            Vector2 p30 = fun.Polar(p1p, 235 * pi / 180, re);




            Vector2 v1 = fun.Polar(p0, 180 * pi / 180 + epsr / 2, (ic / 2) / Math.Sin(epsr / 2) * dxc);
            Vector2 v2 = fun.Polar(p0, -90 * pi / 180 + epsr / 2, (ic / 2) / Math.Cos(epsr / 2) * dxc);
            Vector2 v3 = fun.Polar(p0, epsr / 2, (ic / 2) / Math.Sin(epsr / 2) * dxc);
            Vector2 v4 = fun.Polar(p0, 90 * pi / 180 + epsr / 2, (ic / 2) / Math.Cos(epsr / 2) * dxc);









            LwPolyline poly11 = new LwPolyline();
            poly11.Vertexes.Add(new LwPolylineVertex(p5));
            poly11.Vertexes[0].Bulge = Math.Tan((pi - epsr) / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p6));
            poly11.Vertexes.Add(new LwPolylineVertex(p7));
            poly11.Vertexes[2].Bulge = Math.Tan(epsr / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p8));
            poly11.Vertexes.Add(new LwPolylineVertex(p9));
            poly11.Vertexes[4].Bulge = Math.Tan((pi - epsr) / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p10));
            poly11.Vertexes.Add(new LwPolylineVertex(p11));
            poly11.Vertexes[6].Bulge = Math.Tan(epsr / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p12));
            poly11.Vertexes.Add(new LwPolylineVertex(p5));
            fun.PolyFill(dxf, poly11, 0.5, contour);

            LwPolyline line00 = new LwPolyline();
            line00.Vertexes.Add(new LwPolylineVertex(p1));
            line00.Vertexes.Add(new LwPolylineVertex(p2));
            line00.Vertexes.Add(new LwPolylineVertex(p3));
            line00.Vertexes.Add(new LwPolylineVertex(p4));
            line00.Vertexes.Add(new LwPolylineVertex(p1));
            line00.Lineweight = Lineweight.W25;
            line00.Layer = additionalline;
            dxf.AddEntity(line00);




            Circle circle3 = new Circle(p0, (ic / 2.0));
            circle3.Linetype = Linetype.DashDot;
            circle3.Layer = refin;
            dxf.AddEntity(circle3);



            Line cenline1 = new Line(fun.Polar(p0, pi, (ic / 2) + 2), fun.Polar(p0, 0, (ic / 2) + 2));
            Line cenline2 = new Line(fun.Polar(p0, pi / 2, (ic / 2) + 2), fun.Polar(p0, -pi / 2, (ic / 2) + 2));

            cenline1.Layer = center;
            cenline2.Layer = center;

            cenline1.Linetype = Linetype.Center;
            cenline2.Linetype = Linetype.Center;
            dxf.AddEntity(cenline1);
            dxf.AddEntity(cenline2);

            insert.inserthole(dxf, p0, v2, v3, p20, p21, scale, data);


            DimensionStyle ds = new DimensionStyle("ds");
            ds.ArrowSize = textsize;
            ds.DimArrow1 = DimensionArrowhead.Closedfilled;
            ds.DimArrow2 = DimensionArrowhead.Closedfilled;
            ds.TextHeight = textsize;
            ds.ExtLineExtend = 0.2;
            //标注

            double v10 = fun.CalDistance(p25, p26);
            LinearDimension dimX2 = new LinearDimension(new Line(p2, p3), offset * 1.5, -90, ds);
            dimX2.UserText = "d=" + v10 / scale;
            dxf.AddEntity(dimX2);


            double v20 = fun.CalDistance(p23, p24);
            LinearDimension dimX1 = new LinearDimension(new Line(p23, p24), offset, 180, ds);
            dimX1.UserText = "S=" + v20 / scale;
            dxf.AddEntity(dimX1);


            LinearDimension dimX3 = new LinearDimension(new Line(p4, p3), offset * 2, 0, ds);
            dimX3.UserText = "l";
            dxf.AddEntity(dimX3);

            double v30 = fun.CalDistance(p29, p30);
            LinearDimension dimX4 = new LinearDimension(new Line(p29, p30), offset * 1.5, -180, ds);
            dimX4.UserText = "m1=" + m1 / scale;
            dxf.AddEntity(dimX4);


            double v40 = fun.CalDistance(p27, p28);
            LinearDimension dimX5 = new LinearDimension(new Line(p27, p28), offset * 1.5, 0, ds);
            dimX5.UserText = "m2=" + m2 / scale;
            dxf.AddEntity(dimX5);



            fun.SetLayer(dxf);
            fun.SetByLayer(dxf);


            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2018;
            dxf.Save(path);


        }

        public static void _RhombicInsert1(Dictionary<string, Object> data)    //修光刃正方形刀片
        {
            DxfDocument dxf = new DxfDocument();

            Layer contour = new Layer("contour");//轮廓层
            Layer dimensioning = new Layer("dimensioning");//尺寸层
            Layer refin = new Layer("refin");//基准线/内轮廓/虚线
            Layer center = new Layer("center");//中心线
            Layer textlayer = new Layer("textlayer");//文本层
            Layer hatching = new Layer("hatching");//填充层
            Layer additionalline = new Layer("additionalline");//附加线
            Layer cutting = new Layer("cutting");//切削层
            fun.SetLayer(dxf);

            double offset = 10;
            double textsize = 3.5;

            double tic = Convert.ToDouble(data["ic"]);
            //double scale = Convert.ToDouble(data["scale"]); //放大系数
            double scale = 5; //放大系数

            /*
            double tic = 12.7;
            double scale = 0;
            */
            if (scale == 0 && tic < 9)
            {
                scale = 3.0;
            }
            else if (scale == 0 && tic < 20)
            {
                scale = 2.5;
            }
            else if (scale == 0)
            {
                scale = 2.0;
            }



            string path = Convert.ToString(data["path"]);
            double pi = Math.PI;
            double IC = Convert.ToDouble(data["ic"]) * scale;
            double S = Convert.ToDouble(data["s"]) * scale;
            double L = IC;
            double M = Convert.ToDouble(data["m"]) * scale;
            double BS = Convert.ToDouble(data["bs"]) * scale;
            double EPSR = Convert.ToDouble(data["epsr"]);
            double KRINS = Convert.ToDouble(data["krins"]);
            double KCH = Convert.ToDouble(data["kch"]);
            double AN = Convert.ToDouble(data["an"]);
            double BCH = Convert.ToDouble(data["bch"]) * scale;
            double AS = Convert.ToDouble(data["as"]);
            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            /*
             string path = Convert.ToString(data["path"]);
             double pi = Math.PI;

             double IC = 12.7*scale;
             double S = 4.76 * scale;
             double L = IC;
             double M =0.8 * scale;
             double BS = 1.4 * scale;
             double EPSR = 90;
             double KRINS =75;
             double KCH = 45;
             double AN = 11;
             double BCH = 1 * scale;
             double AS = 11 ;
             */
            //double EPSRN = 75 * (Math.PI / 180);

            double AS_1 = AS * (Math.PI / 180);
            double EPSR_1 = EPSR * (Math.PI / 180);
            double KRINS_1 = KRINS * (Math.PI / 180);
            double An_1 = AN * (Math.PI / 180);
            double KCH_1 = KCH * (Math.PI / 180);



            DimensionStyle dimensionStyle = fun.DimStyle(true);
            DimensionStyle dimensionStyle2 = fun.DimStyle(false);

            if (KRINS == 75 && AN == 0)
            {


                Vector2 v1 = new Vector2(0, 0);
                Vector2 v2 = new Vector2(v1.X - (BS * Math.Cos(EPSR_1 - KRINS_1)), v1.Y + (BS * Math.Sin(EPSR_1 - KRINS_1)));
                Vector2 v3 = new Vector2(v2.X - (BCH * Math.Sin(KCH_1)), v2.Y + BCH * Math.Cos(KCH_1));
                Vector2 v4 = new Vector2(v3.X - (BS * Math.Sin(EPSR_1 - KRINS_1)), v3.Y + (BS * Math.Cos(EPSR_1 - KRINS_1)));
                double length1 = fun.CalDistance(v1, v4);

                Vector2[] Line1 = { v1, v2 };
                fun.drawBLine(dxf, Line1, 0.5, contour);
                Vector2[] Line2 = { v2, v3 };
                fun.drawBLine(dxf, Line2, 0.5, contour);
                Vector2[] Line3 = { v3, v4 };
                fun.drawBLine(dxf, Line3, 0.5, contour);

                Vector2 v18 = new Vector2(v4.X, v1.Y + L / 2);
                Vector2 v19 = new Vector2(v18.X + L, v18.Y);
                Vector2 v20 = new Vector2(v4.X + L / 2, v1.X + L);
                Vector2 v21 = new Vector2(v20.X, v20.Y - L);
                Vector2 v22 = new Vector2(v4.X, v1.Y + L);
                Vector2 v23 = new Vector2(v4.X + L, v1.Y);



                Line Line4 = fun.mirrorline(new Line(v1, v2), v18, v19);
                Vector2[] lsl1 = { new Vector2(Line4.StartPoint.X, Line4.StartPoint.Y), new Vector2(Line4.EndPoint.X, Line4.EndPoint.Y) };
                fun.drawBLine(dxf, lsl1, 0.5, contour);
                Line Line5 = fun.mirrorline(new Line(v2, v3), v18, v19);
                Vector2[] lsl2 = { new Vector2(Line5.StartPoint.X, Line5.StartPoint.Y), new Vector2(Line5.EndPoint.X, Line5.EndPoint.Y) };
                fun.drawBLine(dxf, lsl2, 0.5, contour);
                Line Line6 = fun.mirrorline(new Line(v4, v3), v18, v19);
                Vector2[] lsl3 = { new Vector2(Line6.StartPoint.X, Line6.StartPoint.Y), new Vector2(Line6.EndPoint.X, Line6.EndPoint.Y) };
                fun.drawBLine(dxf, lsl3, 0.5, contour);


                Line Line7 = fun.mirrorline(new Line(v1, v2), v22, v23);
                Vector2[] lsl4 = { new Vector2(Line7.StartPoint.X, Line7.StartPoint.Y), new Vector2(Line7.EndPoint.X, Line7.EndPoint.Y) };
                fun.drawBLine(dxf, lsl4, 0.5, contour);
                Line Line8 = fun.mirrorline(new Line(v3, v2), v22, v23);
                Vector2[] lsl5 = { new Vector2(Line8.StartPoint.X, Line8.StartPoint.Y), new Vector2(Line8.EndPoint.X, Line8.EndPoint.Y) };
                fun.drawBLine(dxf, lsl5, 0.5, contour);
                Line Line9 = fun.mirrorline(new Line(v3, v4), v22, v23);
                Vector2[] lsl6 = { new Vector2(Line9.StartPoint.X, Line9.StartPoint.Y), new Vector2(Line9.EndPoint.X, Line9.EndPoint.Y) };
                fun.drawBLine(dxf, lsl6, 0.5, contour);

                Line Line10 = fun.mirrorline(new Line(v1, v2), v20, v21);
                Vector2[] lsl7 = { new Vector2(Line10.StartPoint.X, Line10.StartPoint.Y), new Vector2(Line10.EndPoint.X, Line10.EndPoint.Y) };
                fun.drawBLine(dxf, lsl7, 0.5, contour);
                Line Line11 = fun.mirrorline(new Line(v3, v2), v20, v21);
                Vector2[] lsl8 = { new Vector2(Line11.StartPoint.X, Line11.StartPoint.Y), new Vector2(Line11.EndPoint.X, Line11.EndPoint.Y) };
                fun.drawBLine(dxf, lsl8, 0.5, contour);
                Line Line12 = fun.mirrorline(new Line(v3, v4), v20, v21);
                Vector2[] lsL9 = { new Vector2(Line12.StartPoint.X, Line12.StartPoint.Y), new Vector2(Line12.EndPoint.X, Line12.EndPoint.Y) };
                fun.drawBLine(dxf, lsL9, 0.5, contour);

                Vector2 v5 = new Vector2(Line6.StartPoint.X, Line6.StartPoint.Y);
                Vector2[] Line13 = { v4, v5 };
                fun.drawBLine(dxf, Line13, 0.5, contour);

                Vector2 v6 = new Vector2(Line6.EndPoint.X, Line6.EndPoint.Y);
                Vector2 v7 = new Vector2(Line4.EndPoint.X, Line4.EndPoint.Y);

                Vector2 v8 = new Vector2(Line4.StartPoint.X, Line4.StartPoint.Y);
                Vector2 v9 = new Vector2(Line9.EndPoint.X, Line9.EndPoint.Y);

                Vector2 v10 = new Vector2(Line9.StartPoint.X, Line9.StartPoint.X);
                Vector2 v11 = new Vector2(Line7.StartPoint.X, Line7.StartPoint.Y);
                Vector2 v14 = new Vector2(Line12.StartPoint.X, Line12.StartPoint.Y);
                Vector2 v15 = new Vector2(Line10.EndPoint.X, Line10.EndPoint.Y);

                Vector2[] Line14 = { v8, v9 };
                fun.drawBLine(dxf, Line14, 0.5, contour);

                Vector2 v12 = new Vector2(Line7.StartPoint.X, Line7.StartPoint.Y);
                Vector2 v13 = new Vector2(Line12.EndPoint.X, Line12.EndPoint.Y);
                Vector2[] Line15 = { v13, v12 };
                fun.drawBLine(dxf, Line15, 0.5, contour);

                Vector2 v16 = new Vector2(Line10.StartPoint.X, Line10.StartPoint.Y);
                Vector2[] Line16 = { v1, v16 };
                fun.drawBLine(dxf, Line16, 0.5, contour);


                Vector2 v17 = new Vector2(v21.X, v21.Y + L / 2);

                Circle circle00 = new Circle(v17, IC / 2);
                circle00.Layer = center;
                circle00.Lineweight = Lineweight.W50;
                circle00.Linetype = Linetype.DashDot;
                dxf.AddEntity(circle00);


                Vector2 v24 = new Vector2(v23.X + L, v1.Y);
                Vector2 v25 = new Vector2(v24.X, v2.Y);
                Vector2 v26 = new Vector2(v24.X, v3.Y);
                Vector2 v27 = new Vector2(v24.X, v4.Y);
                Vector2 v28 = new Vector2(v24.X, v5.Y);
                Vector2 v29 = new Vector2(v24.X, v6.Y);
                Vector2 v30 = new Vector2(v24.X, v7.Y);
                Vector2 v31 = new Vector2(v24.X, v8.Y);
                Vector2 v32 = new Vector2(v31.X + S, v31.Y);
                Vector2 v33 = new Vector2(v32.X, v30.Y);
                Vector2 v34 = new Vector2(v32.X, v29.Y);
                Vector2 v35 = new Vector2(v32.X, v28.Y);
                Vector2 v36 = new Vector2(v32.X, v27.Y);
                Vector2 v37 = new Vector2(v32.X, v26.Y);
                Vector2 v38 = new Vector2(v32.X, v25.Y);
                Vector2 v39 = new Vector2(v32.X, v24.Y);

                Vector2 v40 = new Vector2(v2.X, v1.Y);
                Vector2 v41 = new Vector2(v2.X + v2.Y / Math.Tan(EPSR_1 / 2), v1.Y);

                Vector2 v42 = new Vector2(v15.X + 1.16, v15.Y + 0.3);
                Vector2 v43 = new Vector2(v15.X + 6.09, v15.Y + 4.62);
                Vector2 v44 = new Vector2(v16.X + 1.99, v16.Y);
                Vector2 v45 = new Vector2(v44.X - 0.95, v44.Y - 3.98);

                Vector2[] line29 = { v18, v11 };
                fun.drawBLine(dxf, line29, 0.5, textlayer);

                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(v24));
                poly1.Vertexes.Add(new LwPolylineVertex(v31));
                poly1.Vertexes.Add(new LwPolylineVertex(v32));
                poly1.Vertexes.Add(new LwPolylineVertex(v39));
                poly1.Vertexes.Add(new LwPolylineVertex(v24));

                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);


                Vector2[] line18 = { v26, v37 };
                fun.drawBLine(dxf, line18, 0.5, contour);

                Vector2[] line20 = { v29, v34 };
                fun.drawBLine(dxf, line20, 0.5, contour);

                Vector2[] line22 = { v31, v32 };
                fun.drawBLine(dxf, line22, 0.5, contour);
                Vector2[] Line17 = { v25, v38 };
                fun.drawBLine(dxf, Line17, 0.5, contour);
                Vector2[] line19 = { v28, v35 };
                fun.drawBLine(dxf, line19, 0.5, contour);
                Vector2[] line21 = { v30, v33 };
                fun.drawBLine(dxf, line21, 0.5, contour);
                Vector2[] line23 = { v27, v36 };
                fun.drawBLine(dxf, line23, 0.5, contour);

                LinearDimension dim9 = new LinearDimension(new Line(v3, v2), offset * 2, 134, dimensionStyle2);
                dim9.UserText = "≈1";
                dxf.AddEntity(dim9);
                Angular2LineDimension angdim2 = new Angular2LineDimension(new Line(v41, v40), new Line(v41, v3), offset, dimensionStyle);
                angdim2.UserText = "45°";
                dxf.AddEntity(angdim2);
                LinearDimension dim7 = new LinearDimension(new Line(v15, v16), offset, 165, dimensionStyle2);
                dim7.UserText = "bs";
                dxf.AddEntity(dim7);
                LinearDimension dim8 = new LinearDimension(new Line(v13, v14), offset, 260, dimensionStyle2);
                dim8.UserText = "bs";
                dxf.AddEntity(dim8);
                LinearDimension dim4 = new LinearDimension(new Line(v19, v13), offset, -19, dimensionStyle);
                dim4.UserText = "m";
                dxf.AddEntity(dim4);


                fun.jdbz1(dxf, new Line(v13, v14), new Line(v9, v7), offset, "φ", 1.0);
                fun.jdbz1(dxf, new Line(v44, v1), new Line(v44, v45), offset * 2, "xr＝75°", 0.75);
                fun.jdbz1(dxf, new Line(v22, v12), new Line(v42, v43), offset * 2, "xr＝75°", 0.75);



                //线段尺寸标注
                //尺寸1
                LinearDimension dim1 = new LinearDimension(new Line(v5, v12), offset * 2, 360, dimensionStyle);
                dim1.UserText = "l";
                dxf.AddEntity(dim1);

                LinearDimension dim2 = new LinearDimension(new Line(v1, v8), offset * 2, 90, dimensionStyle);
                dim2.UserText = "l";
                dxf.AddEntity(dim2);
                LinearDimension dim3 = new LinearDimension(new Line(v18, v19), 0, 360, dimensionStyle);
                dim3.UserText = "d";
                dxf.AddEntity(dim3);

                LinearDimension dim5 = new LinearDimension(new Line(v21, v16), offset * 2, 110, dimensionStyle);
                dim5.UserText = "m";
                dxf.AddEntity(dim5);
                LinearDimension dim6 = new LinearDimension(new Line(v24, v39), offset * 1.5, 180, dimensionStyle);
                dim6.UserText = "S";
                dxf.AddEntity(dim6);



                //Angular2LineDimension angdim1 = new Angular2LineDimension(new Line(v23, v19), new Line(v23, v21), offset + 3, dimensionStyle);
                //angdim1.UserText = "εr";
                ///   dxf.AddEntity(angdim1);

                fun.jdbz1(dxf, new Line(v23, v19), new Line(v23, v21), offset, "εr", 0.75);
                fun.jdbz1(dxf, new Line(v16, v15), new Line(v4, v5), offset, "φ", 1.0);



            }

            if (KRINS == 45 && AN == 0)
            {

                Vector2 v1 = new Vector2(0, 0);
                Vector2 v2 = new Vector2(v1.X - (BS * Math.Cos(EPSR_1 - KRINS_1)), v1.Y + (BS * Math.Sin(EPSR_1 - KRINS_1)));
                Vector2 v3 = new Vector2(v2.X - (BCH * Math.Sin(KCH_1)), v2.Y + BCH * Math.Cos(KCH_1));
                Vector2 v4 = new Vector2(v3.X - (BS * Math.Sin(EPSR_1 - KRINS_1)), v3.Y + (BS * Math.Cos(EPSR_1 - KRINS_1)));
                double length1 = fun.CalDistance(v1, v4);






                Vector2 v18 = new Vector2(v4.X, v1.Y + L / 2);
                Vector2 v19 = new Vector2(v18.X + L, v18.Y);
                Vector2 v20 = new Vector2(v4.X + L / 2, v1.X + L);
                Vector2 v21 = new Vector2(v20.X, v20.Y - L);
                Vector2 v22 = new Vector2(v4.X, v1.Y + L);
                Vector2 v23 = new Vector2(v4.X + L, v1.Y);



                Line Line4 = fun.mirrorline(new Line(v1, v2), v18, v19);
                Vector2[] lsl1 = { new Vector2(Line4.StartPoint.X, Line4.StartPoint.Y), new Vector2(Line4.EndPoint.X, Line4.EndPoint.Y) };
                ;
                Line Line5 = fun.mirrorline(new Line(v2, v3), v18, v19);
                Vector2[] lsl2 = { new Vector2(Line5.StartPoint.X, Line5.StartPoint.Y), new Vector2(Line5.EndPoint.X, Line5.EndPoint.Y) };
                ;
                Line Line6 = fun.mirrorline(new Line(v4, v3), v18, v19);
                Vector2[] lsl3 = { new Vector2(Line6.StartPoint.X, Line6.StartPoint.Y), new Vector2(Line6.EndPoint.X, Line6.EndPoint.Y) };



                Line Line7 = fun.mirrorline(new Line(v1, v2), v22, v23);
                Vector2[] lsl4 = { new Vector2(Line7.StartPoint.X, Line7.StartPoint.Y), new Vector2(Line7.EndPoint.X, Line7.EndPoint.Y) };

                Line Line8 = fun.mirrorline(new Line(v3, v2), v22, v23);
                Vector2[] lsl5 = { new Vector2(Line8.StartPoint.X, Line8.StartPoint.Y), new Vector2(Line8.EndPoint.X, Line8.EndPoint.Y) };
                ;
                Line Line9 = fun.mirrorline(new Line(v3, v4), v22, v23);
                Vector2[] lsl6 = { new Vector2(Line9.StartPoint.X, Line9.StartPoint.Y), new Vector2(Line9.EndPoint.X, Line9.EndPoint.Y) };


                Line Line10 = fun.mirrorline(new Line(v1, v2), v20, v21);
                Vector2[] lsl7 = { new Vector2(Line10.StartPoint.X, Line10.StartPoint.Y), new Vector2(Line10.EndPoint.X, Line10.EndPoint.Y) };

                Line Line11 = fun.mirrorline(new Line(v3, v2), v20, v21);
                Vector2[] lsl8 = { new Vector2(Line11.StartPoint.X, Line11.StartPoint.Y), new Vector2(Line11.EndPoint.X, Line11.EndPoint.Y) };

                Line Line12 = fun.mirrorline(new Line(v3, v4), v20, v21);
                Vector2[] lsL9 = { new Vector2(Line12.StartPoint.X, Line12.StartPoint.Y), new Vector2(Line12.EndPoint.X, Line12.EndPoint.Y) };


                Vector2 v5 = new Vector2(Line6.StartPoint.X, Line6.StartPoint.Y);
                Vector2[] Line13 = { v4, v5 };
                fun.drawBLine(dxf, Line13, 0.5, contour);

                Vector2 v6 = new Vector2(Line6.EndPoint.X, Line6.EndPoint.Y);
                Vector2 v7 = new Vector2(Line4.EndPoint.X, Line4.EndPoint.Y);

                Vector2 v8 = new Vector2(Line4.StartPoint.X, Line4.StartPoint.Y);
                Vector2 v9 = new Vector2(Line9.EndPoint.X, Line9.EndPoint.Y);

                Vector2 v10 = new Vector2(Line9.StartPoint.X, Line9.StartPoint.X);
                Vector2 v11 = new Vector2(Line7.StartPoint.X, Line7.StartPoint.Y);
                Vector2 v14 = new Vector2(Line12.StartPoint.X, Line12.StartPoint.Y);
                Vector2 v15 = new Vector2(Line10.EndPoint.X, Line10.EndPoint.Y);

                Vector2[] Line14 = { v8, v9 };
                fun.drawBLine(dxf, Line14, 0.5, contour);

                Vector2 v12 = new Vector2(Line7.StartPoint.X, Line7.StartPoint.Y);
                Vector2 v13 = new Vector2(Line12.EndPoint.X, Line12.EndPoint.Y);
                Vector2[] Line15 = { v13, v12 };
                fun.drawBLine(dxf, Line15, 0.5, contour);

                Vector2 v16 = new Vector2(Line10.StartPoint.X, Line10.StartPoint.Y);
                Vector2[] Line16 = { v1, v16 };
                fun.drawBLine(dxf, Line16, 0.5, contour);



                Vector2 v17 = new Vector2(v21.X, v21.Y + L / 2);


                Vector2[] line24 = { v5, v8 };
                fun.drawBLine(dxf, line24, 0.5, contour);
                Vector2[] line25 = { v9, v12 };
                fun.drawBLine(dxf, line25, 0.5, contour);
                Vector2[] line26 = { v13, v16 };
                fun.drawBLine(dxf, line26, 0.5, contour);
                Vector2[] line27 = { v4, v1 };
                fun.drawBLine(dxf, line27, 0.5, contour);

                Circle circle00 = new Circle(v17, IC / 2);
                circle00.Layer = center;
                circle00.Lineweight = Lineweight.W50;
                circle00.Linetype = Linetype.DashDot;
                dxf.AddEntity(circle00);


                Vector2 v24 = new Vector2(v23.X + L, v1.Y);
                Vector2 v25 = new Vector2(v24.X, v2.Y);
                Vector2 v26 = new Vector2(v24.X, v3.Y);
                Vector2 v27 = new Vector2(v24.X, v4.Y);
                Vector2 v28 = new Vector2(v24.X, v5.Y);
                Vector2 v29 = new Vector2(v24.X, v6.Y);
                Vector2 v30 = new Vector2(v24.X, v7.Y);
                Vector2 v31 = new Vector2(v24.X, v8.Y);
                Vector2 v32 = new Vector2(v31.X + S, v31.Y);
                Vector2 v33 = new Vector2(v32.X, v30.Y);
                Vector2 v34 = new Vector2(v32.X, v29.Y);
                Vector2 v35 = new Vector2(v32.X, v28.Y);
                Vector2 v36 = new Vector2(v32.X, v27.Y);
                Vector2 v37 = new Vector2(v32.X, v26.Y);
                Vector2 v38 = new Vector2(v32.X, v25.Y);
                Vector2 v39 = new Vector2(v32.X, v24.Y);

                Vector2 v40 = new Vector2(v2.X, v1.Y);
                Vector2 v41 = new Vector2(v2.X + v2.Y / Math.Tan(EPSR_1 / 2), v1.Y);

                Vector2 v42 = new Vector2(v15.X + 1.16, v15.Y + 0.3);
                Vector2 v43 = new Vector2(v15.X + 6.09, v15.Y + 4.62);
                Vector2 v44 = new Vector2(v16.X + 1.99, v16.Y);
                Vector2 v45 = new Vector2(v44.X - 0.95, v44.Y - 3.98);



                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(v24));
                poly1.Vertexes.Add(new LwPolylineVertex(v31));
                poly1.Vertexes.Add(new LwPolylineVertex(v32));
                poly1.Vertexes.Add(new LwPolylineVertex(v39));
                poly1.Vertexes.Add(new LwPolylineVertex(v24));

                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);

                Vector2[] line18 = { v26, v37 };
                fun.drawBLine(dxf, line18, 0.5, contour);

                Vector2[] line20 = { v29, v34 };
                fun.drawBLine(dxf, line20, 0.5, contour);

                fun.jdbz1(dxf, new Line(v42, v12), new Line(v42, v43), offset, "xr＝45°", 0.75);



                //线段尺寸标注
                //尺寸1


                LinearDimension dim1 = new LinearDimension(new Line(v5, v12), offset * 2, 360, dimensionStyle);
                dim1.UserText = "l";
                dxf.AddEntity(dim1);

                LinearDimension dim2 = new LinearDimension(new Line(v1, v8), offset * 2, 90, dimensionStyle);
                dim2.UserText = "l";
                dxf.AddEntity(dim2);
                LinearDimension dim3 = new LinearDimension(new Line(v18, v19), 0, 360, dimensionStyle);
                dim3.UserText = "d";
                dxf.AddEntity(dim3);

                LinearDimension dim5 = new LinearDimension(new Line(v21, v16), offset * 2, 110, dimensionStyle);
                dim5.UserText = "m";
                dxf.AddEntity(dim5);
                LinearDimension dim6 = new LinearDimension(new Line(v24, v39), offset * 1.5, 180, dimensionStyle);
                dim6.UserText = "S";
                dxf.AddEntity(dim6);


                fun.jdbz1(dxf, new Line(v23, v19), new Line(v23, v21), offset, "εr", 0.75);
                fun.jdbz1(dxf, new Line(v16, v15), new Line(v4, v5), offset, "φ", 1.0);








            }

            if (KRINS != 0 && AN == 11)
            {
                Vector2 v1 = new Vector2(0, 0);
                Vector2 v2 = new Vector2(v1.X - (BS * Math.Cos(EPSR_1 - KRINS_1)), v1.Y + (BS * Math.Sin(EPSR_1 - KRINS_1)));
                Vector2 v3 = new Vector2(v2.X - (BCH * Math.Sin(KCH_1)), v2.Y + BCH * Math.Cos(KCH_1));

                Vector2[] Line1 = { v1, v2 };
                fun.drawBLine(dxf, Line1, 0.5, contour);

                Vector2[] Line2 = { v3, v2 };
                fun.drawBLine(dxf, Line2, 0.5, contour);

                Vector2 v14 = new Vector2(v3.X, v1.Y + L / 2);
                Vector2 v15 = new Vector2(v14.X + L, v14.Y);
                Vector2 v16 = new Vector2(v14.X + L / 2, v1.Y + L);
                Vector2 v17 = new Vector2(v16.X, v16.Y - L);
                Vector2 v13 = new Vector2(v14.X + L / 2, v14.Y);
                Vector2 v18 = new Vector2(v3.X, v1.Y + L);
                Vector2 v19 = new Vector2(v3.X + L, v1.Y);


                Line line3 = fun.mirrorline(new Line(v1, v2), v14, v15);
                Vector2[] lsline1 = { new Vector2(line3.StartPoint.X, line3.StartPoint.Y), new Vector2(line3.EndPoint.X, line3.EndPoint.Y) };
                fun.drawBLine(dxf, lsline1, 0.5, contour);
                Line line4 = fun.mirrorline(new Line(v2, v3), v14, v15);
                Vector2[] lsline2 = { new Vector2(line4.StartPoint.X, line4.StartPoint.Y), new Vector2(line4.EndPoint.X, line4.EndPoint.Y) };
                fun.drawBLine(dxf, lsline2, 0.5, contour);


                Line line5 = fun.mirrorline(new Line(v1, v2), v18, v19);
                Vector2[] lsline4 = { new Vector2(line5.StartPoint.X, line5.StartPoint.Y), new Vector2(line5.EndPoint.X, line5.EndPoint.Y) };
                fun.drawBLine(dxf, lsline4, 0.5, contour);
                Line line6 = fun.mirrorline(new Line(v3, v2), v18, v19);
                Vector2[] lsline5 = { new Vector2(line6.StartPoint.X, line6.StartPoint.Y), new Vector2(line6.EndPoint.X, line6.EndPoint.Y) };
                fun.drawBLine(dxf, lsline5, 0.5, contour);

                Line line7 = fun.mirrorline(new Line(v1, v2), v16, v17);
                Vector2[] lsline7 = { new Vector2(line7.StartPoint.X, line7.StartPoint.Y), new Vector2(line7.EndPoint.X, line7.EndPoint.Y) };
                fun.drawBLine(dxf, lsline7, 0.5, contour);
                Line line8 = fun.mirrorline(new Line(v3, v2), v16, v17);
                Vector2[] lsline8 = { new Vector2(line8.StartPoint.X, line8.StartPoint.Y), new Vector2(line8.EndPoint.X, line8.EndPoint.Y) };
                fun.drawBLine(dxf, lsline8, 0.5, contour);

                Vector2 v4 = new Vector2(line4.EndPoint.X, line4.EndPoint.Y);
                Vector2 v5 = new Vector2(line3.EndPoint.X, line3.EndPoint.Y);
                Vector2 v6 = new Vector2(line3.StartPoint.X, line3.StartPoint.Y);
                Vector2 v7 = new Vector2(line6.StartPoint.X, line6.StartPoint.Y);
                Vector2 v8 = new Vector2(line6.EndPoint.X, line6.EndPoint.Y);
                Vector2 v9 = new Vector2(line5.StartPoint.X, line5.StartPoint.Y);
                Vector2 v10 = new Vector2(line8.StartPoint.X, line8.StartPoint.Y);
                Vector2 v11 = new Vector2(line7.EndPoint.X, line7.EndPoint.Y);
                Vector2 v12 = new Vector2(line7.StartPoint.X, line7.StartPoint.Y);

                Vector2[] Line9 = { v3, v4 };
                fun.drawBLine(dxf, Line9, 0.5, contour);

                Vector2[] Line10 = { v12, v1 };
                fun.drawBLine(dxf, Line10, 0.5, contour);
                Vector2[] Line11 = { v6, v7 };
                fun.drawBLine(dxf, Line11, 0.5, contour);
                Vector2[] Line12 = { v9, v10 };
                fun.drawBLine(dxf, Line12, 0.5, contour);

                Circle circle00 = new Circle(v13, IC / 2);
                circle00.Layer = center;
                circle00.Lineweight = Lineweight.W50;
                circle00.Linetype = Linetype.DashDot;
                dxf.AddEntity(circle00);


                Vector2 v20 = new Vector2(v15.X + IC * 1.5, v15.Y);
                Vector2 v21 = new Vector2(v20.X - S / 2 * Math.Sin(An_1), v20.Y + S / 2 * Math.Cos(An_1));
                Vector2 v23 = new Vector2(v20.X - S, v20.Y);
                Vector2 v22 = new Vector2(v23.X - S / 2 * Math.Cos(EPSR_1 - An_1), v23.Y + S / 2 * Math.Sin(EPSR_1 - An_1));
                Vector2 v24 = new Vector2(v12.X + 2.5 * L, v12.Y);
                Vector2 v25 = new Vector2(v24.X, v24.Y + L);
                Vector2 v26 = new Vector2(v25.X - S, v25.Y - S * Math.Tan(AS_1));
                Vector2 v27 = new Vector2(v24.X - S, v24.Y + S * Math.Tan(AS_1));

                Vector2 v28 = new Vector2(v24.X - 3, v24.Y);

                Vector2 v29 = new Vector2(v15.X + IC * 3, v15.Y);
                Vector2 v30 = new Vector2(v12.X + 1.31, v12.Y + 0.31);
                Vector2 v31 = new Vector2(v15.X + 12.51, v15.Y - 8.37);

                List<Vector3> points00 = new List<Vector3>
                {
                  new Vector3(v22.X,v22.Y , 0),
                  new Vector3(v22.X+1,v22.Y+0.5 , 0),
                  new Vector3(v22.X+2,v22.Y , 0),
                  new Vector3(v21.X ,v21.Y, 0),
                };

                Spline spline00 = new Spline(points00);
                spline00.Layer = contour;
                DxfDocument doc00 = new DxfDocument();
                dxf.AddEntity(spline00);

                Vector2[] Line13 = { v23, v20 };
                fun.drawBLine(dxf, Line13, 0.5, contour);
                Vector2[] Line14 = { v23, v22 };
                fun.drawBLine(dxf, Line14, 0.5, contour);
                Vector2[] Line15 = { v20, v21 };
                fun.drawBLine(dxf, Line15, 0.5, contour);

                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(v24));
                poly1.Vertexes.Add(new LwPolylineVertex(v25));
                poly1.Vertexes.Add(new LwPolylineVertex(v26));
                poly1.Vertexes.Add(new LwPolylineVertex(v27));
                poly1.Vertexes.Add(new LwPolylineVertex(v24));

                //            poly1.SetConstantWidth(0.05);
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);

                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = poly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = poly1.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)poly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)poly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 5, hline1, harc1, hatching);


                //标注
                LinearDimension dim8 = new LinearDimension(new Line(v10, v11), offset, 235, dimensionStyle2);
                dim8.UserText = "≈1";
                dxf.AddEntity(dim8);


                fun.jdbz1(dxf, new Line(v10, v15), new Line(v10, v29), offset, "37°30′", 0.75 * scale);
                fun.jdbz1(dxf, new Line(v20, v23), new Line(v20, v11), offset * 3, "15°±1°", 0.75 * scale);
                fun.jdbz1(dxf, new Line(v24, v27), new Line(v24, v28), offset * 3, "11°±1°", 0.75 * scale);

                // Angular2LineDimension angdim2 = new Angular2LineDimension(new Line(v10, v15), new Line(v10, v29), offset, dimensionStyle);
                // angdim2.UserText = "37°30′";
                // dxf.AddEntity(angdim2);
                //  Angular2LineDimension angdim6 = new Angular2LineDimension(new Line(v20, v23), (new Line(v20, v11)), offset + 3, dimensionStyle);
                //  angdim6.UserText = "15°±1°";
                // dxf.AddEntity(angdim6);

                // Angular2LineDimension angdim7 = new Angular2LineDimension(new Line(v24, v27), (new Line(v24, v28)), offset + 5, dimensionStyle);
                // angdim7.UserText = "11°±1°";
                //  dxf.AddEntity(angdim7);
                LinearDimension dim1 = new LinearDimension(new Line(v4, v9), offset * 2, 360, dimensionStyle);
                dim1.UserText = "l";
                dxf.AddEntity(dim1);

                LinearDimension dim2 = new LinearDimension(new Line(v1, v6), offset * 2, 90, dimensionStyle);
                dim2.UserText = "l";
                dxf.AddEntity(dim2);
                LinearDimension dim3 = new LinearDimension(new Line(v14, v15), 0, 360, dimensionStyle);
                dim3.UserText = "d";
                dxf.AddEntity(dim3);
                LinearDimension dim4 = new LinearDimension(new Line(v17, v12), offset * 2, 120, dimensionStyle);
                dim4.UserText = "m";
                dxf.AddEntity(dim4);
                // LinearDimension dim5 = new LinearDimension(new Line(v21, v16), offset, 110, dimensionStyle);
                //dim5.UserText = "m";
                //dxf.AddEntity(dim5);
                LinearDimension dim6 = new LinearDimension(new Line(v25, v26), offset * 1.5, 360, dimensionStyle);
                dim6.UserText = "S";
                dxf.AddEntity(dim6);
                LinearDimension dim7 = new LinearDimension(new Line(v11, v12), offset, 197, dimensionStyle2);
                dim7.UserText = "bs";
                dxf.AddEntity(dim7);


                fun.jdbz1(dxf, new Line(v10, v15), new Line(v12, v17), offset, "εr", 0.75 * scale);
                fun.jdbz1(dxf, new Line(v30, v9), new Line(v12, v11), offset * 3, "xr＝75°", 0.75 * scale);
                fun.jdbz1(dxf, new Line(v3, v4), new Line(v12, v11), offset, "φ", 1.0 * scale);



            }

            if (KRINS != 0 && AN == 20)
            {

                Vector2 v1 = new Vector2(0, 0);
                Vector2 v2 = new Vector2(v1.X - (BS * Math.Cos(EPSR_1 - KRINS_1)), v1.Y + (BS * Math.Sin(EPSR_1 - KRINS_1)));
                Vector2 v3 = new Vector2(v2.X - (BCH * Math.Sin(KCH_1)), v2.Y + BCH * Math.Cos(KCH_1));




                Vector2 v14 = new Vector2(v3.X, v1.Y + L / 2);
                Vector2 v15 = new Vector2(v14.X + L, v14.Y);
                Vector2 v16 = new Vector2(v14.X + L / 2, v1.Y + L);
                Vector2 v17 = new Vector2(v16.X, v16.Y - L);
                Vector2 v13 = new Vector2(v14.X + L / 2, v14.Y);
                Vector2 v18 = new Vector2(v3.X, v1.Y + L);
                Vector2 v19 = new Vector2(v3.X + L, v1.Y);


                Line line3 = fun.mirrorline(new Line(v1, v2), v14, v15);
                Vector2[] lsline1 = { new Vector2(line3.StartPoint.X, line3.StartPoint.Y), new Vector2(line3.EndPoint.X, line3.EndPoint.Y) };

                Line line4 = fun.mirrorline(new Line(v2, v3), v14, v15);
                Vector2[] lsline2 = { new Vector2(line4.StartPoint.X, line4.StartPoint.Y), new Vector2(line4.EndPoint.X, line4.EndPoint.Y) };



                Line line5 = fun.mirrorline(new Line(v1, v2), v18, v19);
                Vector2[] lsline4 = { new Vector2(line5.StartPoint.X, line5.StartPoint.Y), new Vector2(line5.EndPoint.X, line5.EndPoint.Y) };

                Line line6 = fun.mirrorline(new Line(v3, v2), v18, v19);
                Vector2[] lsline5 = { new Vector2(line6.StartPoint.X, line6.StartPoint.Y), new Vector2(line6.EndPoint.X, line6.EndPoint.Y) };


                Line line7 = fun.mirrorline(new Line(v1, v2), v16, v17);
                Vector2[] lsline7 = { new Vector2(line7.StartPoint.X, line7.StartPoint.Y), new Vector2(line7.EndPoint.X, line7.EndPoint.Y) };

                Line line8 = fun.mirrorline(new Line(v3, v2), v16, v17);
                Vector2[] lsline8 = { new Vector2(line8.StartPoint.X, line8.StartPoint.Y), new Vector2(line8.EndPoint.X, line8.EndPoint.Y) };


                Vector2 v4 = new Vector2(line4.EndPoint.X, line4.EndPoint.Y);
                Vector2 v5 = new Vector2(line3.EndPoint.X, line3.EndPoint.Y);
                Vector2 v6 = new Vector2(line3.StartPoint.X, line3.StartPoint.Y);
                Vector2 v7 = new Vector2(line6.StartPoint.X, line6.StartPoint.Y);
                Vector2 v8 = new Vector2(line6.EndPoint.X, line6.EndPoint.Y);
                Vector2 v9 = new Vector2(line5.StartPoint.X, line5.StartPoint.Y);
                Vector2 v10 = new Vector2(line8.StartPoint.X, line8.StartPoint.Y);
                Vector2 v11 = new Vector2(line7.EndPoint.X, line7.EndPoint.Y);
                Vector2 v12 = new Vector2(line7.StartPoint.X, line7.StartPoint.Y);

                Vector2[] Line9 = { v3, v4 };
                fun.drawBLine(dxf, Line9, 0.5, contour);

                Vector2[] Line10 = { v12, v1 };
                fun.drawBLine(dxf, Line10, 0.5, contour);
                Vector2[] Line11 = { v6, v7 };
                fun.drawBLine(dxf, Line11, 0.5, contour);
                Vector2[] Line12 = { v9, v10 };
                fun.drawBLine(dxf, Line12, 0.5, contour);

                Vector2[] Line13 = { v4, v6 };
                fun.drawBLine(dxf, Line13, 0.5, contour);
                Vector2[] Line14 = { v7, v9 };
                fun.drawBLine(dxf, Line14, 0.5, contour);
                Vector2[] Line15 = { v1, v3 };
                fun.drawBLine(dxf, Line15, 0.5, contour);
                Vector2[] Line16 = { v12, v10 };
                fun.drawBLine(dxf, Line16, 0.5, contour);



                Circle circle00 = new Circle(v13, IC / 2);
                circle00.Layer = center;
                circle00.Lineweight = Lineweight.W50;
                circle00.Linetype = Linetype.DashDot;
                dxf.AddEntity(circle00);


                Vector2 v20 = new Vector2(v15.X + IC, v15.Y);
                Vector2 v21 = new Vector2(v20.X - S / 2 * Math.Sin(An_1), v20.Y + S / 2 * Math.Cos(An_1));
                Vector2 v23 = new Vector2(v20.X - S, v20.Y);
                Vector2 v22 = new Vector2(v23.X - S / 2 * Math.Cos(EPSR_1 - An_1), v23.Y + S / 2 * Math.Sin(EPSR_1 - An_1));
                Vector2 v24 = new Vector2(v12.X + 2 * L, v12.Y);
                Vector2 v25 = new Vector2(v24.X, v24.Y + L);
                Vector2 v26 = new Vector2(v25.X - S, v25.Y - S * Math.Tan(AS_1));
                Vector2 v27 = new Vector2(v24.X - S, v24.Y + S * Math.Tan(AS_1));

                Vector2 v28 = new Vector2(v24.X - 3, v24.Y);

                Vector2 v29 = new Vector2(v15.X + 5, v15.Y);
                Vector2 v30 = new Vector2(v12.X + 1.31, v12.Y + 0.31);
                Vector2 v31 = new Vector2(v15.X + 12.51, v15.Y - 8.37);

                List<Vector3> points00 = new List<Vector3>
           {
                 new Vector3(v22.X,v22.Y , 0),
               new Vector3(v22.X+1,v22.Y+0.5 , 0),
               new Vector3(v22.X+2,v22.Y , 0),


                  new Vector3(v21.X ,v21.Y, 0),


            };

                Spline spline00 = new Spline(points00);
                spline00.Layer = contour;
                DxfDocument doc00 = new DxfDocument();
                dxf.AddEntity(spline00);

                Vector2[] Line113 = { v23, v20 };
                fun.drawBLine(dxf, Line113, 0.5, contour);
                Vector2[] Line114 = { v23, v22 };
                fun.drawBLine(dxf, Line114, 0.5, contour);
                Vector2[] Line115 = { v20, v21 };
                fun.drawBLine(dxf, Line115, 0.5, contour);

                LwPolyline poly1 = new LwPolyline();
                poly1.Vertexes.Add(new LwPolylineVertex(v24));
                poly1.Vertexes.Add(new LwPolylineVertex(v25));
                poly1.Vertexes.Add(new LwPolylineVertex(v26));
                poly1.Vertexes.Add(new LwPolylineVertex(v27));
                poly1.Vertexes.Add(new LwPolylineVertex(v24));

                //            poly1.SetConstantWidth(0.05);
                poly1.IsClosed = true;
                fun.PolyFill(dxf, poly1, 0.5, contour);

                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = poly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = poly1.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)poly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)poly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 5, hline1, harc1, hatching);





                LinearDimension dim1 = new LinearDimension(new Line(v4, v9), offset * 2, 360, dimensionStyle);
                dim1.UserText = "l";
                dxf.AddEntity(dim1);

                LinearDimension dim2 = new LinearDimension(new Line(v1, v6), offset * 2, 90, dimensionStyle);
                dim2.UserText = "l";
                dxf.AddEntity(dim2);
                LinearDimension dim3 = new LinearDimension(new Line(v14, v15), 0, 360, dimensionStyle);
                dim3.UserText = "d";
                dxf.AddEntity(dim3);
                LinearDimension dim4 = new LinearDimension(new Line(v17, v12), offset * 2, 120, dimensionStyle);
                dim4.UserText = "m";
                dxf.AddEntity(dim4);
                // LinearDimension dim5 = new LinearDimension(new Line(v21, v16), offset, 110, dimensionStyle);
                //dim5.UserText = "m";
                //dxf.AddEntity(dim5);
                LinearDimension dim6 = new LinearDimension(new Line(v25, v26), offset * 1.5, 360, dimensionStyle);
                dim6.UserText = "S";
                dxf.AddEntity(dim6);
                LinearDimension dim7 = new LinearDimension(new Line(v11, v12), offset*2, 197, dimensionStyle2);
                dim7.UserText = "bs";
                dxf.AddEntity(dim7);


                fun.jdbz1(dxf, new Line(v10, v15), new Line(v12, v17), offset, "εr", 0.75);
                fun.jdbz1(dxf, new Line(v30, v9), new Line(v30, v31), offset * 3, "xr＝75°", 0.75);
                fun.jdbz1(dxf, new Line(v3, v4), new Line(v12, v11), offset, "φ", 1.0);
                fun.jdbz1(dxf, new Line(v20, v23), new Line(v20, v11), offset, "20°±30°", 0.75);
                fun.jdbz1(dxf, new Line(v24, v27), new Line(v24, v28), offset, "20°±30°", 0.75);



            }



            Vector2 p0 = new Vector2(IC, 0);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - offset * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }

            fun.SetLayer(dxf);
            fun.SetByLayer(dxf);

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);

        }

        public static void _TrigonInsert(Dictionary<string, Object> data)    //镶式六边形刀片
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour");//轮廓层
            Layer dimensioning = new Layer("dimensioning");//尺寸层
            Layer refin = new Layer("refin");//基准线/内轮廓/虚线
            Layer center = new Layer("center");//中心线
            Layer textlayer = new Layer("textlayer");//文本层
            Layer hatching = new Layer("hatching");//填充层
            Layer additionalline = new Layer("additionalline");//附加线
            Layer cutting = new Layer("cutting");//切削层
            fun.SetLayer(dxf);

            double offset = 10;
            double textsize = 3.5;

            double tic = Convert.ToDouble(data["ic"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数


            if (scale == 0 && tic < 9)
            {
                scale = 3.0;
            }
            else if (scale == 0 && tic < 20)
            {
                scale = 2.0;
            }
            else if (scale == 0)
            {
                scale = 1.5;
            }


            double pi = Math.PI;
            double DIM = Convert.ToDouble(data["dim"]);
            double ic = Convert.ToDouble(data["ic"]) * scale;
            double s = Convert.ToDouble(data["s"]) * scale;
            double d1 = Convert.ToDouble(data["d1"]) * scale;
            double re = Convert.ToDouble(data["re"]) * scale;
            double epsr = Convert.ToDouble(data["epsr"]) * pi / 180;
            double an = Convert.ToDouble(data["an"]) * pi / 180;
            int ifs = (int)Convert.ToDecimal(data["ifs"]);
            int cb = (int)Convert.ToDecimal(data["cb"]);
            string path = Convert.ToString(data["path"]);
            double dxc = 0.80;
            double ictc = Convert.ToDouble(data["ictc"]);
            double stc = Convert.ToDouble(data["stc"]);
            double d1tc = Convert.ToDouble(data["d1tc"]);
            double m = Convert.ToDouble(data["m"]) * scale;
            double le = Convert.ToDouble(data["l"]) * scale;
            double l1 = Convert.ToDouble(data["le"]) * scale;
            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            /*
           double scale = 2;
           double pi = Math.PI;
           double DIM = 1;
           double ic =12.7;
           double s = 4.76;
           double d1 = 3.81;
           double re =1.2;
           double epsr = 80 * pi / 180;
           double an = 0 * pi / 180;
           int ifs = 2;
           int cb = 0;
           string path = Convert.ToString(data["path"]);
           double dxc = 0.80;
           double ictc = 0;
           double stc = 0;
           double d1tc = 0;
            double m = 2.86;
            double le = 8.69;
            double l1 = 3;
           */

            double ang1 = 40 * pi / 180;
            double ang2 = 80 * pi / 180;
            double ang3 = 10 * pi / 180;
            double ang4 = 30 * pi / 180;

            double dis1 = (ic / 2) / Math.Sin(ang1);
            double dis2 = (ic / 2) / Math.Sin(ang2);




            Vector2 p1 = new Vector2(0, 0);
            Vector2 p0 = new Vector2(le * Math.Cos(ang3), (ic / 2) / Math.Cos(ang3));
            Vector2 p2 = new Vector2(p0.X, p1.Y);
            //Vector2 p3 = fun.Polar(p2, ang3, le);
            //Vector2 p4 = fun.Polar(p3, pi - (ang2 - ang3), le);
            Vector2 p3 = fun.Polar(p0, -ang4, dis1);
            Vector2 p4 = fun.Polar(p0, ang4, dis2);

            Vector2 p5 = fun.Polar(p0, pi / 2, dis1);
            Vector2 p6 = fun.Polar(p0, pi - ang4, dis2);
            Vector2 p7 = fun.Polar(p0, pi + ang4, dis1);
            Vector2 p2p = fun.Polar(p2, pi / 2, re / Math.Sin(ang2));
            Vector2 p3p = fun.Polar(p3, pi - ang4, re / Math.Sin(ang1));
            Vector2 p4p = fun.Polar(p4, pi + ang4, re / Math.Sin(ang2));
            Vector2 p5p = fun.Polar(p5, -0.5 * pi, re / Math.Sin(ang1));
            Vector2 p6p = fun.Polar(p6, -ang4, re / Math.Sin(ang2));
            Vector2 p7p = fun.Polar(p7, ang4, re / Math.Sin(ang1));
            Vector2 p8 = fun.Polar(p2, pi - ang3, re / Math.Tan(ang2));
            Vector2 p9 = fun.Polar(p2, ang3, re / Math.Tan(ang2));
            Vector2 p10 = fun.Polar(p3, pi + ang3, re / Math.Tan(ang1));
            Vector2 p11 = fun.Polar(p3, pi - (ang2 - ang3), re / Math.Tan(ang1));
            Vector2 p12 = fun.Polar(p4, ang3 - ang2, re / Math.Tan(ang2));
            Vector2 p13 = fun.Polar(p4, pi - (ang2 - ang4), re / Math.Tan(ang2));
            Vector2 p14 = fun.Polar(p5, ang4 - ang2, re / Math.Tan(ang1));
            Vector2 p15 = fun.Polar(p5, pi + ang2 - ang4, re / Math.Tan(ang1));
            Vector2 p16 = fun.Polar(p6, ang2 - ang4, re / Math.Tan(ang2));
            Vector2 p17 = fun.Polar(p6, pi + ang2 - ang3, re / Math.Tan(ang2));
            Vector2 p18 = fun.Polar(p7, ang2 - ang3, re / Math.Tan(ang1));
            Vector2 p19 = fun.Polar(p7, -ang3, re / Math.Tan(ang1));
            Vector2 p30 = fun.Polar(p5, ang4 - ang2, l1);
            Vector2 p31 = fun.Polar(p5, pi + ang2 - ang4, l1);
            //标注
            Vector2 p32 = fun.Polar(p0, pi / 2, dis1);
            Vector2 p33 = fun.Polar(p0, pi / 2, ic / 2);

            Vector2 p20 = fun.Polar(p0, 0, 3 * ic);
            Vector2 p21 = new Vector2(p20.X, fun.Polar(p5p, pi / 2, re).Y);
            Vector2 p22 = fun.Polar(p21, pi + an, s / Math.Cos(an));
            Vector2 p24 = new Vector2(p20.X, fun.Polar(p2p, -pi / 2, re).Y); ;
            Vector2 p23 = fun.Polar(p24, pi - an, s / Math.Cos(an));





            Vector2 v1 = fun.Polar(p0, -150 * pi / 180, ic / 2 / Math.Sin(40 * pi / 180) * dxc);
            Vector2 v2 = fun.Polar(p0, -90 * pi / 180, ic / 2 / Math.Sin(80 * pi / 180) * dxc);
            Vector2 v4 = fun.Polar(p0, -30 * pi / 180, ic / 2 / Math.Sin(40 * pi / 180) * dxc);
            Vector2 v5 = fun.Polar(p0, 30 * pi / 180, ic / 2 / Math.Sin(80 * pi / 180) * dxc);
            Vector2 v3 = fun.Polar(p0, 90 * pi / 180, ic / 2 / Math.Sin(40 * pi / 180) * dxc);
            Vector2 v6 = fun.Polar(p0, 150 * pi / 180, ic / 2 / Math.Sin(80 * pi / 180) * dxc);


            if (cb == 1 || cb == 2)
            {
                LwPolyline Line01 = new LwPolyline();
                Line01.Vertexes.Add(new LwPolylineVertex(v1));
                Line01.Vertexes.Add(new LwPolylineVertex(v2));
                Line01.Vertexes.Add(new LwPolylineVertex(v4));
                Line01.Vertexes.Add(new LwPolylineVertex(v5));
                Line01.Vertexes.Add(new LwPolylineVertex(v3));
                Line01.Vertexes.Add(new LwPolylineVertex(v6));
                Line01.Vertexes.Add(new LwPolylineVertex(v1));
                Line01.Lineweight = Lineweight.W35;
                Line01.Layer = additionalline;
                dxf.AddEntity(Line01);
            }



            Circle circle2 = new Circle(p0, ic / 2);
            circle2.Layer = refin;
            circle2.Linetype = Linetype.DashDot;
            dxf.AddEntity(circle2);
            Arc arc5 = fun.DrawArc(p14, p5p, p15);

            LwPolyline poly11 = new LwPolyline();
            poly11.Vertexes.Add(new LwPolylineVertex(p8));
            poly11.Vertexes.Add(new LwPolylineVertex(p2));
            poly11.Vertexes.Add(new LwPolylineVertex(p3));
            poly11.Vertexes.Add(new LwPolylineVertex(p4));
            poly11.Vertexes.Add(new LwPolylineVertex(p14));
            poly11.Vertexes[4].Bulge = Math.Tan((pi - epsr) / 4);
            poly11.Vertexes.Add(new LwPolylineVertex(p15));
            poly11.Vertexes.Add(new LwPolylineVertex(p6));
            poly11.Vertexes.Add(new LwPolylineVertex(p7));
            poly11.Vertexes.Add(new LwPolylineVertex(p8));
            poly11.IsClosed = true;
            fun.PolyFill(dxf, poly11, 0.5, contour);

            LwPolyline poly111 = new LwPolyline();
            poly111.Vertexes.Add(new LwPolylineVertex(p30));
            poly111.Vertexes.Add(new LwPolylineVertex(p31));
            poly111.Vertexes.Add(new LwPolylineVertex(p15));
            poly111.Vertexes.Add(new LwPolylineVertex(p14));
            poly111.Vertexes.Add(new LwPolylineVertex(p30));
            poly111.IsClosed = true;
            fun.PolyFill(dxf, poly111, 0.5, contour);
            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            Arc[] harc1 = new Arc[100];
            int hnumst1 = poly111.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = poly111.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)poly111.Explode()[i];
                }
                if (htype1[i] == "Arc")
                {
                    harc1[i] = (Arc)poly111.Explode()[i];
                }
            }
            fun.hatchsub1(dxf, htype1, hnumst1, 45, 1, hline1, harc1, hatching);

            String[] htype2 = new String[100];
            Line[] hline2 = new Line[100];
            Arc[] harc2 = new Arc[100];
            int hnumst2 = poly111.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst2; i++)
            {
                htype2[i] = poly111.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline2[i] = (Line)poly111.Explode()[i];
                }
                if (htype2[i] == "Arc")
                {
                    harc2[i] = (Arc)poly111.Explode()[i];
                }
            }
            fun.hatchsub1(dxf, htype2, hnumst2, 135, 1, hline2, harc2, hatching);



            LwPolyline line00 = new LwPolyline();
            line00.Vertexes.Add(new LwPolylineVertex(p2));
            line00.Vertexes.Add(new LwPolylineVertex(p3));
            line00.Vertexes.Add(new LwPolylineVertex(p4));
            line00.Vertexes.Add(new LwPolylineVertex(p5));
            line00.Vertexes.Add(new LwPolylineVertex(p6));
            line00.Vertexes.Add(new LwPolylineVertex(p7));
            line00.Vertexes.Add(new LwPolylineVertex(p2));
            line00.Lineweight = Lineweight.W25;
            line00.Layer = additionalline;
            dxf.AddEntity(line00);

            insert.inserthole(dxf, p0, v2, v3, p20, p21, scale, data);

            Line cenline1 = new Line(fun.Polar(p0, pi, ic / 2 + 2), fun.Polar(p0, 0, ic / 2 + 2));
            cenline1.Layer = center;
            cenline1.Linetype = Linetype.Center;
            Line cenline2 = new Line(fun.Polar(p0, pi / 2, ic / 2 + 2), fun.Polar(p0, -0.5 * pi, ic / 2 + 2));
            cenline2.Layer = center;
            cenline2.Linetype = Linetype.Center;
            Line cenline3 = new Line(fun.Polar(p20, pi, s + 2), fun.Polar(p20, 0, 2));
            cenline3.Layer = center;
            cenline3.Linetype = Linetype.Center;
            dxf.AddEntity(cenline1);
            dxf.AddEntity(cenline2);
            dxf.AddEntity(cenline3);
            fun.jz(dxf, fun.Polar(fun.Polar(p0, pi / 2, ic / 2), pi, offset + p0.X), 90, 3, "A");


            DimensionStyle dimensionStyle = fun.DimStyle(true);
            DimensionStyle dimensionStyle2 = fun.DimStyle(true);

            double v100 = fun.CalDistance(p32, p33);//计算两点间距离

            //标注


            if (DIM == 0)
            {

                LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi / 2, ic / 2), fun.Polar(p0, -0.5 * pi, ic / 2)), offset + p0.X, 90, dimensionStyle);
                dim1.UserText = "IC";
                dxf.AddEntity(dim1);

                LinearDimension dim2 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                dim1.UserText = "S";
                dxf.AddEntity(dim2);
                //LinearDimension dim3 = new LinearDimension(new Line(p32,p33 ), offset * scale, 90, dimensionStyle);
                //dim3.UserText = "M";
                //dxf.AddEntity(dim3);
                fun.dimrot1(dxf, p32, p33, 90, offset, 2, 1.2, 1.6, 0.9, "  M", "", "");

                Angular2LineDimension dim4 = new Angular2LineDimension(new Line(p5, fun.Polar(p5, epsr / 2, 0.1)), new Line(p5, fun.Polar(p5, pi - epsr / 2, 0.1)), offset, dimensionStyle);
                dim4.UserText = "EPSR";
                dxf.AddEntity(dim4);

                //LinearDimension dim5 = new LinearDimension(new Line(p5, p30), offset * scale*0.8, -45, dimensionStyle);
                //dim5.UserText = "L1";
                //dxf.AddEntity(dim5);
                fun.dimrot1(dxf, p5, p30, -45, offset, 2, 1.2, 1.6, 0.9, "  L1", "", "");

                fun.dimrot1(dxf, p2, p3, -170, offset, 2, 1.2, 1.6, 0.9, "  L", "", "");

                if (re / scale != 0.001)
                {
                    RadialDimension dimrad1 = new RadialDimension(arc5, 147, offset, dimensionStyle);//DimensionStyle.Default);
                    dimrad1.UserText = "RE";
                    dxf.AddEntity(dimrad1);
                }

                if (an != 0)
                {
                    Angular2LineDimension dimang2 = new Angular2LineDimension(new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, dimensionStyle);
                    dimang2.UserText = "AN=" + an * 180 / pi + "°";
                    dxf.AddEntity(dimang2);
                }
            }

            else
            {
                if (ictc == 0)
                {
                    LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi / 2, ic / 2), fun.Polar(p0, -0.5 * pi, ic / 2)), offset + p0.X, 90, dimensionStyle);
                    dim1.UserText = String.Format("IC={0}", ic / scale);
                    dxf.AddEntity(dim1);
                }


                if (ictc != 0)
                {
                    LinearDimension dim1 = new LinearDimension(new Line(fun.Polar(p0, pi / 2, ic / 2), fun.Polar(p0, -0.5 * pi, ic / 2)), offset + p0.X, 90, dimensionStyle);
                    dim1.UserText = String.Format("IC={0}±{1}", ic / scale, ictc);
                    dxf.AddEntity(dim1);
                }
                if (stc == 0)
                {
                    LinearDimension dim2 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                    dim2.UserText = String.Format("S={0}", s / scale);
                    dxf.AddEntity(dim2);
                }
                if (stc != 0)
                {
                    LinearDimension dim2 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                    dim2.UserText = String.Format("S={0}±{1}", s / scale, stc);
                    dxf.AddEntity(dim2);
                }


                LinearDimension dim11 = new LinearDimension(new Line(fun.Polar(p0, pi / 2, ic / 2), fun.Polar(p0, -0.5 * pi, ic / 2)), offset + p0.X, 90, dimensionStyle);
                dim11.UserText = String.Format("IC={0}", ic / scale);
                dxf.AddEntity(dim11);

                LinearDimension dim22 = new LinearDimension(new Line(p23, p24), offset, 180, dimensionStyle);
                dim22.UserText = String.Format("S={0}", s / scale);
                dxf.AddEntity(dim22);

                /*LinearDimension dim33 = new LinearDimension(new Line(p32,p33), offset * scale*1.5, 90, dimensionStyle);
                dim33.UserText = String.Format("M={0}", m  / scale);
                dxf.AddEntity(dim33);
                */

                fun.dimrot1(dxf, p32, p33, 90, offset * 2, 2, 1.2, 1.6, 0.9, "M=" + m, "", "");

                //LinearDimension dim44 = new LinearDimension(new Line(p5, p30), offset * scale * 0.8, -45, dimensionStyle);
                //dim44.UserText = String.Format("L1={0}", l1  / scale);
                // dxf.AddEntity(dim44);

                fun.dimrot1(dxf, p5, p30, -45, offset, 2, 1.2, 1.6, 0.9, "  L1=" + l1, "", "");

                fun.dimrot1(dxf, p2, p3, -170, offset, 2, 1.2, 1.6, 0.9, "  L=" + le, "", "");

                Angular2LineDimension dim4 = new Angular2LineDimension(new Line(p5, fun.Polar(p5, epsr / 2 + ang3, 0.1)), new Line(p5, fun.Polar(p5, epsr / 2 + pi / 2, 0.1)), offset, dimensionStyle);
                dim4.UserText = String.Format("EPSR={0}°", epsr * 180 / pi);
                dxf.AddEntity(dim4);

                if (re / scale != 0.001)
                {
                    RadialDimension dimrad1 = new RadialDimension(arc5, 147, offset, dimensionStyle);//DimensionStyle.Default);
                    dimrad1.UserText = String.Format("RE={0}", re / scale);
                    dxf.AddEntity(dimrad1);
                }

                if (an != 0)
                {
                    Angular2LineDimension dimang2 = new Angular2LineDimension(new Line(p23, fun.Polar(p23, pi - an, 1)), new Line(p24, fun.Polar(p24, pi, 1)), s + offset, dimensionStyle);
                    dimang2.UserText = "AN=" + an * 180 / pi + "°";
                    dxf.AddEntity(dimang2);
                }

            }

            // double isframe = Convert.ToDouble(data["isframe"]);
            // if (isframe == 1)
            /*
            {
                Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 90, p0.Y + 120), data);
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");

            }
            */

            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p1.X - 1189 / 2.0, p1.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p1.X - 841 / 2.0, p1.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p1.X - 594 / 2.0, p1.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p1.X - 420 / 2.0, p1.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p1.X - 297 / 2.0, p1.Y + 210 / 2.0 - offset * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p1.X - 210 / 2.0, p1.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }
            fun.SetLayer(dxf);
            fun.SetByLayer(dxf);


            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }




        public static void Multitooththreadedinserts(Dictionary<string, object> data)
        {

            var dxf = new DxfDocument();
            Layer contour = new Layer("contour");//轮廓层
            Layer dimensioning = new Layer("dimensioning");//尺寸层
            Layer refin = new Layer("refin");//基准线/内轮廓/虚线
            Layer center = new Layer("center");//中心线
            Layer textlayer = new Layer("textlayer");//文本层
            Layer hatching = new Layer("hatching");//填充层
            Layer additionalline = new Layer("additionalline");//附加线
            Layer cutting = new Layer("cutting");//切削层
            fun.SetLayer(dxf);

            double offset = 10;
            double textsize = 3.5;


            //double scale = 10;
            double scale = Convert.ToDouble(data["scale"]);


            string path = Convert.ToString(data["path"]);
            try
            {
                path = Convert.ToString(data["path"]);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            #region 变量
            var holeDia = 3.4;//通孔直径
            try
            {
                holeDia = Convert.ToDouble(data["holedia"]) * scale;
            }
            catch (Exception e)
            {
                Console.WriteLine("[holedia] not found");
            }

            var chamfer4HoleDia = 5.6;//通孔倒角直径
            try
            {
                chamfer4HoleDia = Convert.ToDouble(data["cfdia"]) * scale;
            }
            catch (Exception e)
            {
                Console.WriteLine("[cfdia] not found");
            }


            var icDia = 12.7;//内切圆直径
            try
            {
                icDia = Convert.ToDouble(data["ic"]) * scale;
            }
            catch (Exception e)
            {
                Console.WriteLine("[ic] not found");
            }
            var h = 15.4 / 9.48 * icDia;
            var h1 = 4.16 / 9.48 * icDia;
            try
            {
                h1 = Convert.ToDouble(data["lbb"]) * scale;
            }
            catch (Exception e)
            {
                Console.WriteLine("[lbb] not found");
            }

            var h2 = 1.2 / 9.48 * icDia;
            try
            {
                h2 = Convert.ToDouble(data["pdpt"]) * scale;
            }
            catch (Exception e)
            {
                Console.WriteLine("[pdpt] not found");
            }

            var h3 = 1.133 / 9.48 * icDia;
            try
            {
                h3 = Convert.ToDouble(data["pdpt"]) * scale;
            }
            catch (Exception e)
            {
                Console.WriteLine("[pdpt] not found");
            }

            var l1 = 3.7 / 12.7 * icDia;
            try
            {
                l1 = Convert.ToDouble(data["pdx"]) * scale;
            }
            catch (Exception e)
            {
                Console.WriteLine("[pdx] not found");
            }
            var l2 = 2.4 / 12.7 * icDia;
            try
            {
                l2 = Convert.ToDouble(data["pdy"]) * scale;
            }
            catch (Exception e)
            {
                Console.WriteLine("[pdy] not found");
            }

            var r = 0.25;
            try
            {
                r = Convert.ToDouble(data["cre"]) * scale;
            }
            catch (Exception e)
            {
                Console.WriteLine("[cre] not found");
            }

            //齿左侧圆弧
            var retl = 0.25;
            try
            {
                retl = Convert.ToDouble(data["retl"]) * scale;
            }
            catch (Exception e)
            {
                Console.WriteLine("[retl] not found");
            }

            //齿右侧圆弧
            var retr = 0.25;
            try
            {
                retr = Convert.ToDouble(data["retr"]) * scale;
            }
            catch (Exception e)
            {
                Console.WriteLine("[retr] not found");
            }

            var par = 27.5 * Pi / 180;
            try
            {
                par = Convert.ToDouble(data["par"]) * Pi / 180;
            }
            catch (Exception e)
            {
                Console.WriteLine("[par] not found");
            }

            var pal = 27.5 * Pi / 180;
            try
            {
                pal = Convert.ToDouble(data["pal"]) * Pi / 180;
            }
            catch (Exception e)
            {
                Console.WriteLine("[pal] not found");
            }

            var re = 0.36;
            try
            {
                re = Convert.ToDouble(data["re"]) * Pi / 180;
            }
            catch (Exception e)
            {
                Console.WriteLine("[re] not found");
            }
            //右侧锥度
            var rightDegree = 0 * Pi / 180;
            //左侧锥度
            var leftDegree = 0 * Pi / 180;
            var r1 = 0.8;

            var alpha1 = 15 * Pi / 180;
            try
            {
                alpha1 = Convert.ToDouble(data["gan"]) * Pi / 180;
            }
            catch (Exception e)
            {
                Console.WriteLine("[gan] not found");
            }

            var alpha2 = 45 * Pi / 180;


            // double S = Convert.ToDouble(data["s"]);
            // double S1 = Convert.ToDouble(data["s1"]);
            double S = 1;
            double S1 = 1;

            double thickness;
            double s;
            if (S == 0)
            {
                //刀片厚度
                thickness = 3.65;
                try
                {
                    thickness = Convert.ToDouble(data["s1"]);
                }
                catch (Exception e)
                {
                    Console.WriteLine("[s1] not found");
                }

                s = thickness + h1 * Math.Tan(alpha1 * 180 / Pi);

            }
            if (S1 == 0)
            {
                //刀尖厚度
                s = 3.55;
                try
                {
                    s = Convert.ToDouble(data["s"]);
                }
                catch (Exception e)
                {
                    Console.WriteLine("[s] not found");
                }

                thickness = s - h1 * Math.Tan(alpha1 * 180 / Pi);

            }
            else
            {
                //刀尖厚度
                s = 3.55;
                try
                {
                    s = Convert.ToDouble(data["s"]);
                }
                catch (Exception e)
                {
                    Console.WriteLine("[s] not found");
                }

                //刀片厚度
                thickness = 3.65;
                try
                {
                    thickness = Convert.ToDouble(data["s1"]);
                }
                catch (Exception e)
                {
                    Console.WriteLine("[s1] not found");
                }
            }

            var chamferCD = 60 * Pi / 180;
            try
            {
                chamferCD = Convert.ToDouble(data["cfagl"]) * Pi / 180;
            }
            catch (Exception e)
            {
                Console.WriteLine("[cfagl] not found");
            }
            #endregion


            var hand = "L";
            try
            {
                hand = data["hand"].ToString();
            }
            catch (Exception e)
            {
                Console.WriteLine("[hand] not found");
            }
            var ttp = "EXT";
            try
            {
                hand = data["hand"].ToString();
            }
            catch (Exception e)
            {
                Console.WriteLine("[hand] not found");
            }

            if (hand.Equals("R") && ttp.Equals("EXT") || ttp.Equals("INT") && hand.Equals("L"))

            {
                Vector2 a0 = new Vector2(0, 0);
                Vector2 a1 = fun.Polar(a0, 120 * Pi / 180, icDia / 2 / Math.Cos(60 * Pi / 180));
                Vector2 a2 = fun.Polar(a0, -120 * Pi / 180, icDia / 2 / Math.Cos(60 * Pi / 180));
                Vector2 a3 = fun.Polar(a0, 0 * Pi / 180, icDia / 2 / Math.Cos(60 * Pi / 180));
                LwPolyline line001 = new LwPolyline();
                line001.Vertexes.Add(new LwPolylineVertex(a1));
                line001.Vertexes.Add(new LwPolylineVertex(a2));
                line001.Vertexes.Add(new LwPolylineVertex(a3));
                line001.Vertexes.Add(new LwPolylineVertex(a1));
                line001.Layer = contour;
                dxf.AddEntity(line001);

                var origin = new Vector2(0, 0);
                var v1 = fun.Polar(origin, 180 * Pi / 180, icDia / 2);
                var v2 = fun.Polar(v1, 90 * Pi / 180, (icDia / 2) / Math.Tan(30 * Pi / 180));
                var v3 = new Vector2(v2.X + l1, v2.Y - l2);
                var v3p = fun.Polar(origin, 90 * Pi / 180, icDia / 13 * 7);
                var v4 = fun.Inters(v3, fun.Polar(v3, (-90 * Pi / 180 + par), 1), v3p, fun.Polar(v3p, 0, 1));
                var v6 = fun.Polar(origin, 60 * Pi / 180, icDia / 2);
                var v5 = fun.Inters(v4, fun.Polar(v4, 0, 1), v2, v6);
                var v7 = fun.Polar(v3, (-90 * Pi / 180 - pal), fun.CalDistance(v3, v4) * 0.9);
                var v8 = fun.Polar(v7, 90 * Pi / 180 + par, fun.CalDistance(v3, v7) * 0.9);
                var v9 = fun.Polar(v8, (-90 * Pi / 180 - pal), fun.CalDistance(v7, v8));
                var v10 = fun.Polar(v9, 90 * Pi / 180 + par, fun.CalDistance(v8, v9));
                var v11 = fun.Inters(v10, fun.Polar(v10, (-90 * Pi / 180 - pal), 1), v2, v1);


                var contoureLine1 = Pus.AddPointsToLwPolyLine(v1, v11, v10, v9, v8, v7, v3, v4, v5, v6);
                contoureLine1.Layer = contour;
                var contoureLine2 = Pus.Fillet4LwPline(contoureLine1, 2, re / 2);
                var contoureLine3 = Pus.Fillet4LwPline(contoureLine2, 4, re / 2);
                var contoureLine4 = Pus.Fillet4LwPline(contoureLine3, 6, re / 2);
                var contoureLine5 = Pus.Fillet4LwPline(contoureLine4, 8, re / 2);
                var contoureLine6 = Pus.Fillet4LwPline(contoureLine5, 10, re / 2);
                var contoureLine = Pus.Fillet4LwPline(contoureLine6, 12, re / 2);
                //dxf.AddEntity(contoureLine7);
                fun.PolyFill(dxf, contoureLine, 0.3, contour);


                var holeC = new Circle(origin, holeDia / 2);
                holeC.Layer = contour;
                //dxf.AddEntity(holeC);
                fun.drawcircle(dxf, origin, holeDia / 2, 0.3, contour);
                var chamferC = new Circle(origin, chamfer4HoleDia / 2);
                chamferC.Layer = contour;
                //dxf.AddEntity(chamferC);
                fun.drawcircle(dxf, origin, chamfer4HoleDia / 2, 0.3, contour);
                var ic = new Circle(origin, icDia / 2);
                ic.Layer = center;
                dxf.AddEntity(ic);
                //fun.drawcircle(dxf, origin, icDia / 2, 0.3, contour);
                var le = icDia / Math.Tan(Pi / 6);//理论边长（从动），由内切圆尺寸驱动
                var hf = h - le / 2;

                var p1 = new Vector2(origin.X + icDia / 2, origin.Y);
                var p3 = new Vector2(p1.X, p1.Y + hf - h2);
                var p2 = new Vector2(p3.X, p3.Y + h2 - h1);


                var cornerRadiusCenter = new Vector2(p3.X - l1, p3.Y + h2 - r);
                var p6 = Vector2.Polar(cornerRadiusCenter, r, par);
                var p7 = Vector2.Polar(cornerRadiusCenter, r, Pi - pal);
                var p7p = Vector2.Polar(p7, 1, -Pi / 2 - pal);
                var p6p = Vector2.Polar(p6, 1, -Pi / 2 + par);
                var p3p = Vector2.Polar(p3, 1, rightDegree);

                var cp = fun.Inters(p6, p6p, p3, p3p);
                var p4 = Vector2.Polar(cp, retr / Math.Tan(Pi / 4 + par / 2 + rightDegree / 2), -rightDegree);
                var p5 = Vector2.Polar(cp, retr / Math.Tan(Pi / 4 + par / 2 + rightDegree / 2), Pi / 2 + par);

                var ll1 = new Vector2(1, cornerRadiusCenter.Y + r - h3);
                var ll2 = new Vector2(2, cornerRadiusCenter.Y + r - h3);
                var cl = fun.Inters(ll1, ll2, p7, p7p);

                var p8 = Vector2.Polar(cl, retl / Math.Tan(Pi / 4 + pal / 2 - leftDegree / 2), Pi / 2 - pal);
                var p9 = Vector2.Polar(cl, retl / Math.Tan(Pi / 4 + pal / 2 - leftDegree / 2), Pi - leftDegree);
                var p11 = Vector2.Polar(origin, icDia / 2, 2 * Pi / 3);

                var p11p = Vector2.Polar(p11, 1, Pi / 6);
                var p10 = fun.Inters(p11, p11p, cl, p9);
                var p12 = fun.Inters(p10, p11, p2, Vector2.Polar(p2, 1, Pi));
                var line1 = new Line(new Vector2(-p2.X, p2.Y), new Vector2(-p12.X, p12.Y));
                //line1.Layer = contour;
                //dxf.AddEntity(line1);
                fun.drawBline(dxf, line1, 0.3, contour);
                //fun.drawBLine(dxf, line1, 0.3, contour);
                //dxf.AddEntity(Pus.RotateByOrigin(Pi * 2 / 3,line1));
                //dxf.AddEntity(Pus.RotateByOrigin(-Pi * 2 / 3, line1));
                fun.drawBline(dxf, Pus.RotateByOrigin(Pi * 2 / 3, line1), 0.3, contour);
                fun.drawBline(dxf, Pus.RotateByOrigin(-Pi * 2 / 3, line1), 0.3, contour);
                //旋转
                var contourLine1 = Pus.RotateByOrigin(Pi * 2 / 3, contoureLine);
                //dxf.AddEntity(contourLine1);
                fun.PolyFill(dxf, contourLine1, 0.3, contour);
                //再旋转
                var contourLine2 = Pus.RotateByOrigin(-Pi * 2 / 3, contoureLine);
                //dxf.AddEntity(contourLine2);
                fun.PolyFill(dxf, contourLine2, 0.3, contour);

                //断屑槽
                var d1 = new Vector2(origin.X + le * 1.5, origin.Y);
                var d2 = new Vector2(d1.X, d1.Y + holeDia / 2);
                var d3 = new Vector2(d2.X, p3.Y);
                var d2p = Pus.KPoint(d2, d3, 0.2);
                var d4 = new Vector2(d1.X, d1.Y + hf);
                var d5 = new Vector2(d4.X - s, d4.Y);
                var d6 = Vector2.Polar(d5, h2 / Math.Cos(alpha1), -Pi / 2 + alpha1);
                var d9 = new Vector2(d1.X - thickness, p12.Y);
                var dc = fun.Inters(d5, d6, d9, Vector2.Polar(d9, 1, Pi / 4));
                var distance = r1 * Math.Tan((alpha1 + alpha2) / 2);
                var d7 = Vector2.Polar(dc, distance, alpha1 + Pi / 2);
                var d8 = Vector2.Polar(dc, distance, -Pi / 2 - alpha2);
                var d10 = new Vector2(d1.X - thickness, d1.Y + chamfer4HoleDia / 2);
                var d11 = Vector2.Polar(d10, (chamfer4HoleDia - holeDia) / (2 * Math.Sin(chamferCD / 2)), -chamferCD / 2);
                var breaker1 = Pus.AddPointsToLwPolyLine(d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d2);
                breaker1.Vertexes[6].Bulge = -Math.Tan((alpha1 + alpha2) / 4);
                breaker1.Layer = contour;
                //dxf.AddEntity(breaker1);
                fun.PolyFill(dxf, breaker1, 0.3, contour);
                var line3_6 = new Line(d3, d6);
                line3_6.Layer = contour;
                //dxf.AddEntity(line3_6);
                fun.drawBline(dxf, line3_6, 0.3, contour);
                var d12 = new Vector2(d1.X, d1.Y - holeDia / 2);
                var d13 = new Vector2(d11.X, d12.Y);
                var d14 = new Vector2(d10.X, d10.Y - chamfer4HoleDia);
                var d15 = Vector2.Polar(d14, 1, -Pi / 2);
                var d16 = new Vector2(d12.X, d15.Y);
                var holeLine = Pus.AddPointsToLwPolyLine(d1, d12, d13, d14, d10);
                holeLine.Layer = contour;
                //dxf.AddEntity(holeLine);
                fun.PolyFill(dxf, holeLine, 0.3, contour);
                var line11_13 = new Line(d11, d13);
                line11_13.Layer = contour;
                //dxf.AddEntity(line11_13);
                fun.drawBline(dxf, line11_13, 0.3, contour);

                var line14_15 = new Line(d14, d15);
                line14_15.Layer = contour;
                //dxf.AddEntity(line14_15);
                fun.drawBline(dxf, line14_15, 0.3, contour);

                var line12_16 = new Line(d12, d16);
                line12_16.Layer = contour;
                //dxf.AddEntity(line12_16);
                fun.drawBline(dxf, line12_16, 0.3, contour);

                /*
                var s1 = Pus.TwoPointsSpline(d9, d2p, 7, 3);
                s1.Layer = hatching;
                dxf.AddEntity(s1);*/

                LwPolyline line00 = new LwPolyline();
                line00.Vertexes.Add(new LwPolylineVertex(d9));
                line00.Vertexes.Add(new LwPolylineVertex(new Vector2((d9.X + d2p.X) / 2, (d9.Y + d2p.Y) / 2)));
                line00.Vertexes[0].Bulge = Math.Tan(30 * Pi / 180 / 4);
                line00.Vertexes.Add(new LwPolylineVertex(d2p));
                line00.Vertexes[1].Bulge = Math.Tan(-30 * Pi / 180 / 4);
                line00.Layer = hatching;
                line00.Lineweight = Lineweight.W25;
                dxf.AddEntity(line00);

                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(d9));
                poly2.Vertexes.Add(new LwPolylineVertex(new Vector2((d9.X + d2p.X) / 2, (d9.Y + d2p.Y) / 2)));
                poly2.Vertexes[0].Bulge = Math.Tan(30 * Pi / 180 / 4);
                poly2.Vertexes.Add(new LwPolylineVertex(d2p));
                poly2.Vertexes[1].Bulge = Math.Tan(-30 * Pi / 180 / 4);
                poly2.Vertexes.Add(new LwPolylineVertex(d2));
                poly2.Vertexes.Add(new LwPolylineVertex(d11));
                poly2.Vertexes.Add(new LwPolylineVertex(d10));
                poly2.Vertexes.Add(new LwPolylineVertex(d9));
                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = poly2.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = poly2.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)poly2.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)poly2.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 2, hline1, harc1, hatching);




                /*
                var hatch1 = Pus.HatchByPath(new List<EntityObject>() { Pus.AddPointsToLwPolyLine(d2p, d2, d11, d10, d9), s1 }, 45, 3);
                hatch1.Layer = hatching;
                dxf.AddEntity(hatch1);*/




                /*
                var s2 = Pus.TwoPointsSpline(d15, d16, 7, 4);
                s2.Layer = hatching;
                dxf.AddEntity(s2);
                var hatch2 = Pus.HatchByPath(new List<EntityObject>() { Pus.AddPointsToLwPolyLine(d16, d12, d13, d14, d15), s2 }, 45, 3);
                hatch2.Layer = hatching;
                dxf.AddEntity(hatch2);*/

                LwPolyline line01 = new LwPolyline();
                line01.Vertexes.Add(new LwPolylineVertex(d15));
                line01.Vertexes.Add(new LwPolylineVertex(new Vector2((d15.X + d16.X) / 2, (d15.Y + d16.Y) / 2)));
                line01.Vertexes[0].Bulge = Math.Tan(30 * Pi / 180 / 4);
                line01.Vertexes.Add(new LwPolylineVertex(d16));
                line01.Vertexes[1].Bulge = Math.Tan(-30 * Pi / 180 / 4);
                line01.Layer = hatching;
                line01.Lineweight = Lineweight.W25;
                dxf.AddEntity(line01);

                LwPolyline poly3 = new LwPolyline();
                poly3.Vertexes.Add(new LwPolylineVertex(d15));
                poly3.Vertexes.Add(new LwPolylineVertex(new Vector2((d15.X + d16.X) / 2, (d15.Y + d16.Y) / 2)));
                poly3.Vertexes[0].Bulge = Math.Tan(30 * Pi / 180 / 4);
                poly3.Vertexes.Add(new LwPolylineVertex(d16));
                poly3.Vertexes[1].Bulge = Math.Tan(-30 * Pi / 180 / 4);
                poly3.Vertexes.Add(new LwPolylineVertex(d12));
                poly3.Vertexes.Add(new LwPolylineVertex(d13));
                poly3.Vertexes.Add(new LwPolylineVertex(d14));
                poly3.Vertexes.Add(new LwPolylineVertex(d15));
                String[] htype2 = new String[100];
                Line[] hline2 = new Line[100];
                Arc[] harc2 = new Arc[100];
                int hnumst2 = poly3.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst2; i++)
                {
                    htype2[i] = poly3.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype2[i] == "Line")
                    {
                        hline2[i] = (Line)poly3.Explode()[i];
                    }
                    if (htype2[i] == "Arc")
                    {
                        harc2[i] = (Arc)poly3.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype2, hnumst2, 45, 2, hline2, harc2, hatching);



                //局部放大图
                var scaling = 3.0;
                var sm2 = Matrix2.Identity * scaling;//缩放vector2的矩阵
                var scalLine0 = Pus.ScalingByMatrix2(contoureLine, sm2);
                var scalLine = Pus.OffsetLwPolyline(scalLine0, new Vector2(-10, 5));
                //dxf.AddEntity(scalLine);
                fun.PolyFill(dxf, scalLine, 0.3, contour);



                //标注
                DimensionStyle dimensionStyle = fun.DimStyle(true);
                DimensionStyle dimensionStyle2 = fun.DimStyle(false);



                var dim_ic = new DiametricDimension(ic, -45, offset, dimensionStyle);
                dim_ic.UserText = "IC = " + Math.Round(icDia, 4);
                dxf.AddEntity(dim_ic);

                /*
                var arc1Dim = Pus.ReDimension(scalLine, 1, dimensionStyle, 45, offset);
                arc1Dim.UserText = "" + Math.Round(retr,4);
                dxf.AddEntity(arc1Dim);

                var arc2Dim = Pus.ReDimension(scalLine, 2, dimensionStyle, 90, offset);
                arc2Dim.UserText = "" + Math.Round(r,4);
                dxf.AddEntity(arc2Dim);

                var arc3Dim = Pus.ReDimension(scalLine, 3, dimensionStyle, 130, offset);
                arc3Dim.UserText = "" + Math.Round(retl,4);
                dxf.AddEntity(arc3Dim);*/



                var arc2 = Pus.GetArcFromPline(scalLine, 5);
                var arc2Cen = Pus.ToV2(arc2.Center);

                var dim_h2 = new LinearDimension(new Line(sm2 * p3, new Vector2(arc2Cen.X, arc2Cen.Y + r * scaling)), offset * 4, -90, dimensionStyle);
                dim_h2.UserText = Math.Round(h2, 4) + "";
                //dxf.AddEntity(dim_h2);


                var arc2CenP = new Vector2(arc2Cen.X, fun.Polar(arc2Cen, -90 * Pi / 180, 10).Y);
                var cenLine = new Line(fun.Polar(arc2Cen, 90 * Pi / 180, 5), arc2CenP);
                cenLine.Layer = center;
                dxf.AddEntity(cenLine);
                /*
                var dim_l1 = new LinearDimension(new Line(sm2 * p3, arc2Cen), - offset * 6, 0, dimensionStyle);
                dim_l1.UserText = Math.Round(l1, 4) + "";
                dxf.AddEntity(dim_l1);*/



                var dim_Par =
                      new Angular2LineDimension(cenLine, new Line(scalLine.Vertexes[10].Position, scalLine.Vertexes[9].Position), offset * 4, dimensionStyle);
                dim_Par.UserText = "PAR=" + Math.Round(par * 180 / Pi, 4) + "°";
                dxf.AddEntity(dim_Par);

                var dim_Pal =
                    new Angular2LineDimension(cenLine, new Line(scalLine.Vertexes[11].Position, scalLine.Vertexes[12].Position), offset * 4, dimensionStyle);
                dim_Pal.UserText = "PAL=" + Math.Round(pal * 180 / Pi, 4) + "°";
                dxf.AddEntity(dim_Pal);

                //刀片厚度
                var dim_thickness = new LinearDimension(new Line(d15, d16), offset, 180, dimensionStyle2);
                dim_thickness.UserText = "S1=" + Math.Round(thickness, 4) + "";
                dxf.AddEntity(dim_thickness);

                //刀尖厚度
                var dim_s = new LinearDimension(new Line(d4, d5), offset*2, 0, dimensionStyle2);
                dim_s.UserText = "S=" + Math.Round(s, 4) + "";
                dxf.AddEntity(dim_s);

                //前角
                var dim_alpha1 =
                    new Angular2LineDimension(new Line(d5, Vector2.Polar(d5, 1, Pi / 2)), new Line(d5, Vector2.Polar(d5, 1, Vector2.Angle(d6, d5))), offset * 1, dimensionStyle2);
                dim_alpha1.UserText = "GAN=" + Math.Round(alpha1 * 180 / Pi, 4) + "°";
                dxf.AddEntity(dim_alpha1);
                //Pus.NeedleDim(dxf, new Line(d5, Vector2.Polar(d5, 1, Pi / 2)), new Line(d5, Vector2.Polar(d5, 1, Vector2.Angle(d6, d5))), offset * 4, Math.Round(alpha1 * 180 / Pi, 4) + "°", dimensionStyle);

                //孔直径
                var dim_holedia = new LinearDimension(new Line(d2, d12), offset + Math.Abs(d11.X - d2.X), -90, dimensionStyle);
                dim_holedia.UserText = "HOLEDIA=" + Math.Round(holeDia, 4) + "";
                dxf.AddEntity(dim_holedia);

                //段屑槽长度
                var dim_breaker = new LinearDimension(new Line(d5, d9), offset, 90, dimensionStyle);
                dim_breaker.UserText = "LBB=" + Math.Round(h1, 3) + "";
                dxf.AddEntity(dim_breaker);

                //沉头孔角度
                /*
                var dim_chamfer =
                    new Angular2LineDimension(new Line(d11, d10), new Line(d13, d14), offset * 4.5, dimensionStyle);
                dim_chamfer.UserText = Math.Round(chamferCD * 180 / Pi, 2) + "°";
                dxf.AddEntity(dim_chamfer);*/

                fun.jdbz1(dxf, new Line(d11, d10), new Line(d13, d14), offset * 3 + d10.Y / Math.Tan(chamferCD / 2), Math.Round(chamferCD * 180 / Pi, 2) + "°", 1.5);

                //沉头孔最大直径
                var dim_chamferDia = new LinearDimension(new Line(d10, d14), offset, 90, dimensionStyle);
                dim_chamferDia.UserText = "CFDIA=" + Math.Round(chamfer4HoleDia, 3) + "";
                dxf.AddEntity(dim_chamferDia);

                //PDX
                LinearDimension pdx = new LinearDimension(new Line(contoureLine1.Vertexes[6].Position, a1), offset + Math.Abs(contoureLine1.Vertexes[6].Position.Y - a1.Y), 0, dimensionStyle);
                pdx.UserText = String.Format("PDX={0}", l1);
                dxf.AddEntity(pdx);
                //PDY
                LinearDimension pdy = new LinearDimension(new Line(contoureLine1.Vertexes[6].Position, a1), offset + Math.Abs(contoureLine1.Vertexes[6].Position.X - a1.X), 90, dimensionStyle);
                pdy.UserText = String.Format("PDY={0}", l2);
                dxf.AddEntity(pdy);
            }
            else
            {
                Vector2 a0 = new Vector2(0, 0);
                Vector2 a1 = fun.Polar(a0, 60 * Pi / 180, icDia / 2 / Math.Cos(60 * Pi / 180));
                Vector2 a2 = fun.Polar(a0, -60 * Pi / 180, icDia / 2 / Math.Cos(60 * Pi / 180));
                Vector2 a3 = fun.Polar(a0, 180 * Pi / 180, icDia / 2 / Math.Cos(60 * Pi / 180));
                LwPolyline line001 = new LwPolyline();
                line001.Vertexes.Add(new LwPolylineVertex(a1));
                line001.Vertexes.Add(new LwPolylineVertex(a2));
                line001.Vertexes.Add(new LwPolylineVertex(a3));
                line001.Vertexes.Add(new LwPolylineVertex(a1));
                line001.Layer = contour;
                dxf.AddEntity(line001);

                var origin = new Vector2(0, 0);
                var v1 = fun.Polar(origin, 180 * Pi / 180, icDia / 2);
                var v2 = fun.Polar(v1, 90 * Pi / 180, (icDia / 2) / Math.Tan(30 * Pi / 180));
                var v3 = new Vector2(v2.X + l1, v2.Y - l2);
                var v3p = fun.Polar(origin, 90 * Pi / 180, icDia / 13 * 7);
                var v4 = fun.Inters(v3, fun.Polar(v3, (-90 * Pi / 180 + par), 1), v3p, fun.Polar(v3p, 0, 1));
                var v6 = fun.Polar(origin, 60 * Pi / 180, icDia / 2);
                var v5 = fun.Inters(v4, fun.Polar(v4, 0, 1), v2, v6);
                var v7 = fun.Polar(v3, (-90 * Pi / 180 - pal), fun.CalDistance(v3, v4) * 0.9);
                var v8 = fun.Polar(v7, 90 * Pi / 180 + par, fun.CalDistance(v3, v7) * 0.9);
                var v9 = fun.Polar(v8, (-90 * Pi / 180 - pal), fun.CalDistance(v7, v8));
                var v10 = fun.Polar(v9, 90 * Pi / 180 + par, fun.CalDistance(v8, v9));
                var v11 = fun.Inters(v10, fun.Polar(v10, (-90 * Pi / 180 - pal), 1), v2, v1);


                var contoureLine1_1 = Pus.AddPointsToLwPolyLine(v1, v11, v10, v9, v8, v7, v3, v4, v5, v6);
                var contoureLine1 = Pus.MirrorPolyline(contoureLine1_1, new Vector2(0, 0), new Vector2(0, 1));
                contoureLine1.Layer = contour;
                var contoureLine2 = Pus.Fillet4LwPline(contoureLine1, 2, re / 2);
                var contoureLine3 = Pus.Fillet4LwPline(contoureLine2, 4, re / 2);
                var contoureLine4 = Pus.Fillet4LwPline(contoureLine3, 6, re / 2);
                var contoureLine5 = Pus.Fillet4LwPline(contoureLine4, 8, re / 2);
                var contoureLine6 = Pus.Fillet4LwPline(contoureLine5, 10, re / 2);
                var contoureLine = Pus.Fillet4LwPline(contoureLine6, 12, re / 2);
                //dxf.AddEntity(contoureLine7);
                fun.PolyFill(dxf, contoureLine, 0.3, contour);


                var holeC = new Circle(origin, holeDia / 2);
                holeC.Layer = contour;
                //dxf.AddEntity(holeC);
                fun.drawcircle(dxf, origin, holeDia / 2, 0.3, contour);
                var chamferC = new Circle(origin, chamfer4HoleDia / 2);
                chamferC.Layer = contour;
                //dxf.AddEntity(chamferC);
                fun.drawcircle(dxf, origin, chamfer4HoleDia / 2, 0.3, contour);
                var ic = new Circle(origin, icDia / 2);
                ic.Layer = center;
                dxf.AddEntity(ic);
                //fun.drawcircle(dxf, origin, icDia / 2, 0.3, contour);
                var le = icDia / Math.Tan(Pi / 6);//理论边长（从动），由内切圆尺寸驱动
                var hf = h - le / 2;

                var p1 = new Vector2(origin.X + icDia / 2, origin.Y);
                var p3 = new Vector2(p1.X, p1.Y + hf - h2);
                var p2 = new Vector2(p3.X, p3.Y + h2 - h1);


                var cornerRadiusCenter = new Vector2(p3.X - l1, p3.Y + h2 - r);
                var p6 = Vector2.Polar(cornerRadiusCenter, r, par);
                var p7 = Vector2.Polar(cornerRadiusCenter, r, Pi - pal);
                var p7p = Vector2.Polar(p7, 1, -Pi / 2 - pal);
                var p6p = Vector2.Polar(p6, 1, -Pi / 2 + par);
                var p3p = Vector2.Polar(p3, 1, rightDegree);

                var cp = fun.Inters(p6, p6p, p3, p3p);
                var p4 = Vector2.Polar(cp, retr / Math.Tan(Pi / 4 + par / 2 + rightDegree / 2), -rightDegree);
                var p5 = Vector2.Polar(cp, retr / Math.Tan(Pi / 4 + par / 2 + rightDegree / 2), Pi / 2 + par);

                var ll1 = new Vector2(1, cornerRadiusCenter.Y + r - h3);
                var ll2 = new Vector2(2, cornerRadiusCenter.Y + r - h3);
                var cl = fun.Inters(ll1, ll2, p7, p7p);

                var p8 = Vector2.Polar(cl, retl / Math.Tan(Pi / 4 + pal / 2 - leftDegree / 2), Pi / 2 - pal);
                var p9 = Vector2.Polar(cl, retl / Math.Tan(Pi / 4 + pal / 2 - leftDegree / 2), Pi - leftDegree);
                var p11 = Vector2.Polar(origin, icDia / 2, 2 * Pi / 3);

                var p11p = Vector2.Polar(p11, 1, Pi / 6);
                var p10 = fun.Inters(p11, p11p, cl, p9);
                var p12 = fun.Inters(p10, p11, p2, Vector2.Polar(p2, 1, Pi));
                var line1_1 = new Line(new Vector2(-p2.X, p2.Y), new Vector2(-p12.X, p12.Y));
                var line1 = fun.mirrorline(line1_1, new Vector2(0, 0), new Vector2(0, 1));
                //line1.Layer = contour;
                //dxf.AddEntity(line1);
                fun.drawBline(dxf, line1, 0.3, contour);
                //fun.drawBLine(dxf, line1, 0.3, contour);
                //dxf.AddEntity(Pus.RotateByOrigin(Pi * 2 / 3,line1));
                //dxf.AddEntity(Pus.RotateByOrigin(-Pi * 2 / 3, line1));
                fun.drawBline(dxf, Pus.RotateByOrigin(Pi * 2 / 3, line1), 0.3, contour);
                fun.drawBline(dxf, Pus.RotateByOrigin(-Pi * 2 / 3, line1), 0.3, contour);
                //旋转
                var contourLine1 = Pus.RotateByOrigin(Pi * 2 / 3, contoureLine);
                //dxf.AddEntity(contourLine1);
                fun.PolyFill(dxf, contourLine1, 0.3, contour);
                //再旋转
                var contourLine2 = Pus.RotateByOrigin(-Pi * 2 / 3, contoureLine);
                //dxf.AddEntity(contourLine2);
                fun.PolyFill(dxf, contourLine2, 0.3, contour);

                //断屑槽
                var d1 = new Vector2(origin.X - le, origin.Y);
                var d2 = new Vector2(d1.X, d1.Y + holeDia / 2);
                var d3 = new Vector2(d2.X, p3.Y);
                var d2p = Pus.KPoint(d2, d3, 0.2);
                var d4 = new Vector2(d1.X, d1.Y + hf);
                var d5 = new Vector2(d4.X - s, d4.Y);
                var d6 = Vector2.Polar(d5, h2 / Math.Cos(alpha1), -Pi / 2 + alpha1);
                var d9 = new Vector2(d1.X - thickness, p12.Y);
                var dc = fun.Inters(d5, d6, d9, Vector2.Polar(d9, 1, Pi / 4));
                var distance = r1 * Math.Tan((alpha1 + alpha2) / 2);
                var d7 = Vector2.Polar(dc, distance, alpha1 + Pi / 2);
                var d8 = Vector2.Polar(dc, distance, -Pi / 2 - alpha2);
                var d10 = new Vector2(d1.X - thickness, d1.Y + chamfer4HoleDia / 2);
                var d11 = Vector2.Polar(d10, (chamfer4HoleDia - holeDia) / (2 * Math.Sin(chamferCD / 2)), -chamferCD / 2);
                var breaker1 = Pus.AddPointsToLwPolyLine(d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d2);
                breaker1.Vertexes[6].Bulge = -Math.Tan((alpha1 + alpha2) / 4);
                breaker1.Layer = contour;
                //dxf.AddEntity(breaker1);
                fun.PolyFill(dxf, breaker1, 0.3, contour);
                var line3_6 = new Line(d3, d6);
                line3_6.Layer = contour;
                //dxf.AddEntity(line3_6);
                fun.drawBline(dxf, line3_6, 0.3, contour);
                var d12 = new Vector2(d1.X, d1.Y - holeDia / 2);
                var d13 = new Vector2(d11.X, d12.Y);
                var d14 = new Vector2(d10.X, d10.Y - chamfer4HoleDia);
                var d15 = Vector2.Polar(d14, 1, -Pi / 2);
                var d16 = new Vector2(d12.X, d15.Y);
                var holeLine = Pus.AddPointsToLwPolyLine(d1, d12, d13, d14, d10);
                holeLine.Layer = contour;
                //dxf.AddEntity(holeLine);
                fun.PolyFill(dxf, holeLine, 0.3, contour);
                var line11_13 = new Line(d11, d13);
                line11_13.Layer = contour;
                //dxf.AddEntity(line11_13);
                fun.drawBline(dxf, line11_13, 0.3, contour);

                var line14_15 = new Line(d14, d15);
                line14_15.Layer = contour;
                //dxf.AddEntity(line14_15);
                fun.drawBline(dxf, line14_15, 0.3, contour);

                var line12_16 = new Line(d12, d16);
                line12_16.Layer = contour;
                //dxf.AddEntity(line12_16);
                fun.drawBline(dxf, line12_16, 0.3, contour);

                /*
                var s1 = Pus.TwoPointsSpline(d9, d2p, 7, 3);
                s1.Layer = hatching;
                dxf.AddEntity(s1);*/

                LwPolyline line00 = new LwPolyline();
                line00.Vertexes.Add(new LwPolylineVertex(d9));
                line00.Vertexes.Add(new LwPolylineVertex(new Vector2((d9.X + d2p.X) / 2, (d9.Y + d2p.Y) / 2)));
                line00.Vertexes[0].Bulge = Math.Tan(30 * Pi / 180 / 4);
                line00.Vertexes.Add(new LwPolylineVertex(d2p));
                line00.Vertexes[1].Bulge = Math.Tan(-30 * Pi / 180 / 4);
                line00.Layer = hatching;
                line00.Lineweight = Lineweight.W25;
                dxf.AddEntity(line00);

                LwPolyline poly2 = new LwPolyline();
                poly2.Vertexes.Add(new LwPolylineVertex(d9));
                poly2.Vertexes.Add(new LwPolylineVertex(new Vector2((d9.X + d2p.X) / 2, (d9.Y + d2p.Y) / 2)));
                poly2.Vertexes[0].Bulge = Math.Tan(30 * Pi / 180 / 4);
                poly2.Vertexes.Add(new LwPolylineVertex(d2p));
                poly2.Vertexes[1].Bulge = Math.Tan(-30 * Pi / 180 / 4);
                poly2.Vertexes.Add(new LwPolylineVertex(d2));
                poly2.Vertexes.Add(new LwPolylineVertex(d11));
                poly2.Vertexes.Add(new LwPolylineVertex(d10));
                poly2.Vertexes.Add(new LwPolylineVertex(d9));
                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = poly2.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = poly2.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)poly2.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)poly2.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 2, hline1, harc1, hatching);




                /*
                var hatch1 = Pus.HatchByPath(new List<EntityObject>() { Pus.AddPointsToLwPolyLine(d2p, d2, d11, d10, d9), s1 }, 45, 3);
                hatch1.Layer = hatching;
                dxf.AddEntity(hatch1);*/




                /*
                var s2 = Pus.TwoPointsSpline(d15, d16, 7, 4);
                s2.Layer = hatching;
                dxf.AddEntity(s2);
                var hatch2 = Pus.HatchByPath(new List<EntityObject>() { Pus.AddPointsToLwPolyLine(d16, d12, d13, d14, d15), s2 }, 45, 3);
                hatch2.Layer = hatching;
                dxf.AddEntity(hatch2);*/

                LwPolyline line01 = new LwPolyline();
                line01.Vertexes.Add(new LwPolylineVertex(d15));
                line01.Vertexes.Add(new LwPolylineVertex(new Vector2((d15.X + d16.X) / 2, (d15.Y + d16.Y) / 2)));
                line01.Vertexes[0].Bulge = Math.Tan(30 * Pi / 180 / 4);
                line01.Vertexes.Add(new LwPolylineVertex(d16));
                line01.Vertexes[1].Bulge = Math.Tan(-30 * Pi / 180 / 4);
                line01.Layer = hatching;
                line01.Lineweight = Lineweight.W25;
                dxf.AddEntity(line01);

                LwPolyline poly3 = new LwPolyline();
                poly3.Vertexes.Add(new LwPolylineVertex(d15));
                poly3.Vertexes.Add(new LwPolylineVertex(new Vector2((d15.X + d16.X) / 2, (d15.Y + d16.Y) / 2)));
                poly3.Vertexes[0].Bulge = Math.Tan(30 * Pi / 180 / 4);
                poly3.Vertexes.Add(new LwPolylineVertex(d16));
                poly3.Vertexes[1].Bulge = Math.Tan(-30 * Pi / 180 / 4);
                poly3.Vertexes.Add(new LwPolylineVertex(d12));
                poly3.Vertexes.Add(new LwPolylineVertex(d13));
                poly3.Vertexes.Add(new LwPolylineVertex(d14));
                poly3.Vertexes.Add(new LwPolylineVertex(d15));
                String[] htype2 = new String[100];
                Line[] hline2 = new Line[100];
                Arc[] harc2 = new Arc[100];
                int hnumst2 = poly3.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst2; i++)
                {
                    htype2[i] = poly3.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype2[i] == "Line")
                    {
                        hline2[i] = (Line)poly3.Explode()[i];
                    }
                    if (htype2[i] == "Arc")
                    {
                        harc2[i] = (Arc)poly3.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype2, hnumst2, 45, 2, hline2, harc2, hatching);



                //局部放大图
                var scaling = 3.0;
                var sm2 = Matrix2.Identity * scaling;//缩放vector2的矩阵
                var scalLine0 = Pus.ScalingByMatrix2(contoureLine, sm2);
                var scalLine = Pus.OffsetLwPolyline(scalLine0, new Vector2(10, 5));
                //dxf.AddEntity(scalLine);
                fun.PolyFill(dxf, scalLine, 0.3, contour);


                //标注
                DimensionStyle dimensionStyle = fun.DimStyle(true);
                DimensionStyle dimensionStyle2 = fun.DimStyle(false);


                var dim_ic = new DiametricDimension(ic, -45, offset, dimensionStyle);
                dim_ic.UserText = "IC = " + Math.Round(icDia, 4);
                dxf.AddEntity(dim_ic);

                /*
                var arc1Dim = Pus.ReDimension(scalLine, 1, dimensionStyle, 45, offset);
                arc1Dim.UserText = "" + Math.Round(retr,4);
                dxf.AddEntity(arc1Dim);

                var arc2Dim = Pus.ReDimension(scalLine, 2, dimensionStyle, 90, offset);
                arc2Dim.UserText = "" + Math.Round(r,4);
                dxf.AddEntity(arc2Dim);

                var arc3Dim = Pus.ReDimension(scalLine, 3, dimensionStyle, 130, offset);
                arc3Dim.UserText = "" + Math.Round(retl,4);
                dxf.AddEntity(arc3Dim);*/



                var arc2 = Pus.GetArcFromPline(scalLine, 5);
                var arc2Cen = Pus.ToV2(arc2.Center);

                var dim_h2 = new LinearDimension(new Line(sm2 * p3, new Vector2(arc2Cen.X, arc2Cen.Y + r * scaling)), offset * 4, -90, dimensionStyle);
                dim_h2.UserText = Math.Round(h2, 4) + "";
                //dxf.AddEntity(dim_h2);


                var arc2CenP = new Vector2(arc2Cen.X, fun.Polar(arc2Cen, -90 * Pi / 180, 10).Y);
                var cenLine = new Line(fun.Polar(arc2Cen, 90 * Pi / 180, 5), arc2CenP);
                cenLine.Layer = center;
                dxf.AddEntity(cenLine);
                /*
                var dim_l1 = new LinearDimension(new Line(sm2 * p3, arc2Cen), - offset * 6, 0, dimensionStyle);
                dim_l1.UserText = Math.Round(l1, 4) + "";
                dxf.AddEntity(dim_l1);*/



                var dim_Par =
                      new Angular2LineDimension(cenLine, new Line(scalLine.Vertexes[10].Position, scalLine.Vertexes[9].Position), offset * 4, dimensionStyle);
                dim_Par.UserText = "PAR=" + Math.Round(par * 180 / Pi, 4) + "°";
                dxf.AddEntity(dim_Par);

                var dim_Pal =
                    new Angular2LineDimension(cenLine, new Line(scalLine.Vertexes[11].Position, scalLine.Vertexes[12].Position), offset * 4, dimensionStyle);
                dim_Pal.UserText = "PAL=" + Math.Round(pal * 180 / Pi, 4) + "°";
                dxf.AddEntity(dim_Pal);

                //刀片厚度
                var dim_thickness = new LinearDimension(new Line(d15, d16), offset, 180, dimensionStyle2);
                dim_thickness.UserText = "S1=" + Math.Round(thickness, 4) + "";
                dxf.AddEntity(dim_thickness);

                //刀尖厚度
                var dim_s = new LinearDimension(new Line(d4, d5), offset, 0, dimensionStyle2);
                dim_s.UserText = "S=" + Math.Round(s, 4) + "";
                dxf.AddEntity(dim_s);

                //前角
                var dim_alpha1 =
                    new Angular2LineDimension(new Line(d5, Vector2.Polar(d5, 1, Pi / 2)), new Line(d5, Vector2.Polar(d5, 1, Vector2.Angle(d6, d5))), offset * 3, dimensionStyle2);
                dim_alpha1.UserText = "GAN=" + Math.Round(alpha1 * 180 / Pi, 4) + "°";
                dxf.AddEntity(dim_alpha1);
                //Pus.NeedleDim(dxf, new Line(d5, Vector2.Polar(d5, 1, Pi / 2)), new Line(d5, Vector2.Polar(d5, 1, Vector2.Angle(d6, d5))), offset * 4, Math.Round(alpha1 * 180 / Pi, 4) + "°", dimensionStyle);

                //孔直径
                var dim_holedia = new LinearDimension(new Line(d2, d12), offset + Math.Abs(d11.X - d2.X), -90, dimensionStyle);
                dim_holedia.UserText = "HOLEDIA=" + Math.Round(holeDia, 4) + "";
                dxf.AddEntity(dim_holedia);

                //段屑槽长度
                var dim_breaker = new LinearDimension(new Line(d5, d9), offset, 90, dimensionStyle);
                dim_breaker.UserText = "LBB=" + Math.Round(h1, 3) + "";
                dxf.AddEntity(dim_breaker);

                //沉头孔角度
                /*
                var dim_chamfer =
                    new Angular2LineDimension(new Line(d11, d10), new Line(d13, d14), offset * 4.5, dimensionStyle);
                dim_chamfer.UserText = Math.Round(chamferCD * 180 / Pi, 2) + "°";
                dxf.AddEntity(dim_chamfer);*/

                fun.jdbz1(dxf, new Line(d11, d10), new Line(d13, d14), offset * 2 + d10.Y / Math.Tan(chamferCD / 2), Math.Round(chamferCD * 180 / Pi, 2) + "°", 1.5);

                //沉头孔最大直径
                var dim_chamferDia = new LinearDimension(new Line(d10, d14), offset, 90, dimensionStyle);
                dim_chamferDia.UserText = "CFDIA=" + Math.Round(chamfer4HoleDia, 3) + "";
                dxf.AddEntity(dim_chamferDia);

                //PDX
                LinearDimension pdx = new LinearDimension(new Line(contoureLine1.Vertexes[6].Position, a1), offset + Math.Abs(contoureLine1.Vertexes[6].Position.Y - a1.Y), 0, dimensionStyle);
                pdx.UserText = String.Format("PDX={0}", l1);
                dxf.AddEntity(pdx);
                //PDY
                LinearDimension pdy = new LinearDimension(new Line(contoureLine1.Vertexes[6].Position, a1), offset + Math.Abs(contoureLine1.Vertexes[6].Position.X - a1.X), 90, dimensionStyle);
                pdy.UserText = String.Format("PDY={0}", l2);
                dxf.AddEntity(pdy);
            }


            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);

            Vector2 p0 = new Vector2(0, 0);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - offset * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }


            fun.SetLayer(dxf);
            fun.SetByLayer(dxf);



            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
            Console.WriteLine("生成DXF文件" + path);
        }

        public static void CombBlade(Dictionary<string, object> data)
        {

            var dxf = new DxfDocument();
            Layer contour = new Layer("contour");//轮廓层
            Layer dimensioning = new Layer("dimensioning");//尺寸层
            Layer refin = new Layer("refin");//基准线/内轮廓/虚线
            Layer center = new Layer("center");//中心线
            Layer textlayer = new Layer("textlayer");//文本层
            Layer hatching = new Layer("hatching");//填充层
            Layer additionalline = new Layer("additionalline");//附加线
            Layer cutting = new Layer("cutting");//切削层
            fun.SetLayer(dxf);

            double offset = 10;
            double textsize = 3.5;


            //double scale = 5; //放大系数
            double scale = Convert.ToDouble(data["scale"]); //放大系数

            string path = Convert.ToString(data["path"]);
            try
            {
                path = Convert.ToString(data["path"]);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            // #region 变量







            //总长
            var l = 25.0;
            try
            {
                l = Convert.ToDouble(data["insl"]) * scale;
            }
            catch (Exception e)
            {
                Console.WriteLine("[l] not found");
            }
            //螺距
            var p = 2.5;
            try
            {
                p = Convert.ToDouble(data["tp"]) * scale;
            }
            catch (Exception e)
            {
                Console.WriteLine("[p] not found");
            }
            //齿长
            var le = 25.0;
            try
            {
                le = Convert.ToDouble(data["le"]) * scale;
            }
            catch (Exception e)
            {
                Console.WriteLine("[le] not found");
            }
            //刀片厚度
            var h = 3.5;
            try
            {
                h = Convert.ToDouble(data["s1"]) * scale;
            }
            catch (Exception e)
            {
                Console.WriteLine("[h] not found");
            }
            //刀片宽度
            var H = 7.08;
            try
            {
                H = Convert.ToDouble(data["w1"]) * scale;
            }
            catch (Exception e)
            {
                Console.WriteLine("[H] not found");
            }
            //轮廓夹角
            var β = 60 * Pi / 180;
            try
            {
                β = Convert.ToDouble(data["pna"]) * Pi / 180;
            }
            catch (Exception e)
            {
                Console.WriteLine("[β] not found");
            }
            //轮廓深度
            var h1 = 1.44;
            try
            {
                h1 = Convert.ToDouble(data["popt"]) * scale;
            }
            catch (Exception e)
            {
                Console.WriteLine("[h1] not found");
            }



            var v1 = new Vector2(0, 0);
            var v0 = fun.Polar(v1, Pi, (l - le) / 2);
            var v2 = fun.Polar(v1, 0, le);
            var v3 = fun.Polar(v2, 0, (l - le) / 2);
            var v4 = fun.Polar(v3, -90 * Pi / 180, (H - h1));
            var v5 = new Vector2(v0.X, v4.Y);
            var v6 = fun.Polar(v0, -90 * Pi / 180, 0.195 * (H - h1));
            var v7 = new Vector2(v4.X, v6.Y);
            var v8 = fun.Polar(v0, -90 * Pi / 180, 0.946 * (H - h1));
            var v9 = new Vector2(v4.X, v8.Y);

            var y1 = 0.098 * H;
            var y2 = 0.116 * H;
            var y3 = 0.169 * H;

            var c1 = new Vector2(v5.X + 0.34 * l, v8.Y + y3);
            var c2 = fun.Polar(c1, 0, 0.462 * l);
            var c3 = new Vector2(c2.X + 0.115 * l, c2.Y + 0.18 * H);


            //齿形
            var L = p * 3 / 4;
            var l1 = p * 3 / 8;
            var α = 90 * Pi / 180 - β / 2;
            var γ = α;
            var h2 = l1 * Math.Tan(α);
            var h3 = h2 - h1;
            var l2 = h3 / h2 * L;
            var l3 = l2 / 2;
            var r = l3 / Math.Tan(γ / 2);
            var h4 = h1 - r;

            var p1 = v1;
            var p2 = fun.Polar(p1, 0, p / 8);
            var p3p4 = new Vector2(p2.X + l1, p2.Y + h4);
            var p3 = fun.Polar(p3p4, 90 * Pi / 180 + γ, r);
            var p4 = fun.Polar(p3p4, 90 * Pi / 180 - γ, r);
            var p5 = fun.Polar(p2, 0, L);
            var p6 = fun.Polar(p5, 0, p * 1 / 8);
            var p7 = fun.Polar(p3p4, 90 * Pi / 180, 5 * r);
            var p8 = fun.Polar(p3p4, -90 * Pi / 180, 20 * r);

            var line1 = new Line(p1, p2);
            var line2 = new Line(p2, p3);
            var line3 = new Line(p4, p5);
            var line4 = new Line(p5, p6);
            var line04 = new Line(p7, p8);
            var arc1 = new Arc(p3p4, r, 90 - γ * 180 / Pi, 90 + γ * 180 / Pi);
            double n = le / p;
            int n1;
            n1 = (int)n;
            Console.WriteLine("value:" + n1.ToString());

            Line[] linepoarray1 = new Line[1000];
            linepoarray1 = fun.arrayrline(line1, n1 + 1, 2, p, 10);
            for (int i = 1; i <= n1; i++)
            {
                fun.drawBline(dxf, linepoarray1[i], 0.2, contour);
            }
    ;
            Line[] linepoarray2 = new Line[1000];
            linepoarray2 = fun.arrayrline(line2, n1 + 1, 2, p, 10);
            for (int i = 1; i <= n1; i++)
            {

                fun.drawBline(dxf, linepoarray2[i], 0.2, contour);
            }
    ;
            Line[] linepoarray3 = new Line[1000];
            linepoarray3 = fun.arrayrline(line3, n1 + 1, 2, p, 10);
            for (int i = 1; i <= n1; i++)
            {

                fun.drawBline(dxf, linepoarray3[i], 0.2, contour);
            }
    ;
            Line[] linepoarray4 = new Line[1000];
            linepoarray4 = fun.arrayrline(line4, n1 + 1, 2, p, 10);
            for (int i = 1; i <= n1; i++)
            {
                fun.drawBline(dxf, linepoarray4[i], 0.2, contour);
            }
    ;
            Line[] linepoarray6 = new Line[1000];
            linepoarray6 = fun.arrayrline(line04, n1 + 1, 2, p, 10);
            for (int i = 1; i <= n1; i++)
            {

                linepoarray6[i].Layer = center;
                linepoarray6[i].Lineweight = Lineweight.W25;
                linepoarray6[i].LinetypeScale = 0.25;
                linepoarray6[i].Linetype = Linetype.DashDot;
                dxf.AddEntity(linepoarray6[i]);
            }
    ;
            Arc[] linepoarray5 = new Arc[1000];
            linepoarray5 = fun.arrayrarc(arc1, n1 + 1, 2, p, 10);
            for (int i = 1; i <= n1; i++)
            {
                fun.drawBArc(dxf, linepoarray5[i], 0.2, contour);
            }
    ;

            var polyline1 = Pus.AddPointsToLwPolyLine(v2, v3, v4, v5, v0, v1);
            fun.PolyFill(dxf, polyline1, 0.2, contour);
            var line6 = new Line(v6, v7);
            var line7 = new Line(v8, v9);
            fun.drawBline(dxf, line6, 0.2, contour);
            fun.drawBline(dxf, line7, 0.2, contour);

            var polyline2 = Pus.AddPointsToLwPolyLine(fun.Polar(c1, 0, y1), fun.Polar(c1, Pi, y1), fun.Polar(c1, 0, y1));
            polyline2.Vertexes[0].Bulge = Math.Tan(180 * Math.PI / 180 / 4);
            polyline2.Vertexes[1].Bulge = Math.Tan(180 * Math.PI / 180 / 4);
            fun.PolyFill(dxf, polyline2, 0.2, contour);
            var polyline3 = Pus.AddPointsToLwPolyLine(fun.Polar(c1, 0, y3), fun.Polar(c1, Pi, y3), fun.Polar(c1, 0, y3));
            polyline3.Vertexes[0].Bulge = Math.Tan(180 * Math.PI / 180 / 4);
            polyline3.Vertexes[1].Bulge = Math.Tan(180 * Math.PI / 180 / 4);
            fun.PolyFill(dxf, polyline3, 0.2, contour);
            var polyline4 = Pus.AddPointsToLwPolyLine(fun.Polar(c2, 0, y1), fun.Polar(c2, Pi, y1), fun.Polar(c2, 0, y1));
            polyline4.Vertexes[0].Bulge = Math.Tan(180 * Math.PI / 180 / 4);
            polyline4.Vertexes[1].Bulge = Math.Tan(180 * Math.PI / 180 / 4);
            fun.PolyFill(dxf, polyline4, 0.2, contour);
            var polyline5 = Pus.AddPointsToLwPolyLine(fun.Polar(c2, 0, y3), fun.Polar(c2, Pi, y3), fun.Polar(c2, 0, y3));
            polyline5.Vertexes[0].Bulge = Math.Tan(180 * Math.PI / 180 / 4);
            polyline5.Vertexes[1].Bulge = Math.Tan(180 * Math.PI / 180 / 4);
            fun.PolyFill(dxf, polyline5, 0.2, contour);
            var polyline6 = Pus.AddPointsToLwPolyLine(fun.Polar(c3, 0, y2), fun.Polar(c3, Pi, y2), fun.Polar(c3, 0, y2));
            polyline6.Vertexes[0].Bulge = Math.Tan(180 * Math.PI / 180 / 4);
            polyline6.Vertexes[1].Bulge = Math.Tan(180 * Math.PI / 180 / 4);
            fun.PolyFill(dxf, polyline6, 0.2, contour);

            var line8 = new Line(fun.Polar(c1, 0, y3 * 2), fun.Polar(c1, Pi, y3 * 2));
            line8.Layer = center;
            line8.Lineweight = Lineweight.W25;
            line8.LinetypeScale = 0.25;
            line8.Linetype = Linetype.DashDot;
            dxf.AddEntity(line8);
            var line9 = new Line(fun.Polar(c2, 0, y3 * 2), fun.Polar(c2, Pi, y3 * 2));
            line9.Layer = center;
            line9.Lineweight = Lineweight.W25;
            line9.LinetypeScale = 0.25;
            line9.Linetype = Linetype.DashDot;
            dxf.AddEntity(line9);
            var line10 = new Line(fun.Polar(c3, 0, y3 * 2), fun.Polar(c3, Pi, y3 * 2));
            line10.Layer = center;
            line10.Lineweight = Lineweight.W25;
            line10.LinetypeScale = 0.25;
            line10.Linetype = Linetype.DashDot;
            dxf.AddEntity(line10);



            //侧视图
            var v10 = new Vector2(v3.X + h * 5, fun.Polar(p3p4, 90 * Pi / 180, r).Y);
            var v11 = fun.Polar(v10, 0, h);
            var v12 = new Vector2(v11.X, v4.Y);
            var v13 = new Vector2(v10.X, v12.Y);
            var v14 = fun.Polar(v10, 0, 0.04 * h);
            var v15 = fun.Polar(v14, -73 * Pi / 180, 0.256 * H);
            var v16 = new Vector2(v10.X, v6.Y);
            var z1 = new Vector2(v10.X + h / 2, v10.Y + h / 2);
            var z2 = new Vector2(z1.X, v12.Y - h / 2);
            var z3 = new Vector2(v10.X - h / 2, c1.Y);
            var z4 = new Vector2(v11.X + h / 2, z3.Y);
            var z5 = new Vector2(v11.X - 0.4 * h, c3.Y);
            var z6 = new Vector2(v11.X + 0.1 * h, z5.Y);
            var v17 = fun.mirrorpoint(v16, z1, z2);
            var v18 = fun.mirrorpoint(v15, z1, z2);
            var v19 = fun.mirrorpoint(v14, z1, z2);
            var v20 = new Vector2(v10.X, c1.Y + y3);
            var v21 = new Vector2(v10.X + h * 3 / 16, c1.Y + y2);
            var v22 = new Vector2(v10.X + h * 3 / 16, c1.Y - y2);
            var v23 = new Vector2(v10.X, c1.Y - y3);
            var v24 = fun.mirrorpoint(v20, z1, z2);
            var v25 = fun.mirrorpoint(v21, z1, z2);
            var v26 = fun.mirrorpoint(v22, z1, z2);
            var v27 = fun.mirrorpoint(v23, z1, z2);
            var v28 = fun.Polar(new Vector2(v11.X, z5.Y), 90 * Pi / 180, y2 * 7 / 8);
            var v29 = fun.Polar(new Vector2(v11.X, z5.Y), -90 * Pi / 180, y2 * 7 / 8);

            var polyline7 = Pus.AddPointsToLwPolyLine(v14, v15, v16, v13, v12, v17, v18, v19, v14);
            var polyline8 = Pus.Fillet4LwPline(polyline7, 1, 0.156 * h);
            var polyline9 = Pus.Fillet4LwPline(polyline8, 7, 0.156 * h);
            fun.PolyFill(dxf, polyline9, 0.2, contour);

            Line line11 = new Line(z1, z2);
            line11.Layer = center;
            line11.Lineweight = Lineweight.W25;
            line11.Linetype = Linetype.DashDot;
            dxf.AddEntity(line11);
            Line line12 = new Line(z3, z4);
            line12.Layer = center;
            line12.Lineweight = Lineweight.W25;
            line12.Linetype = Linetype.DashDot;
            dxf.AddEntity(line12);
            Line line13 = new Line(z5, z6);
            line13.Layer = center;
            line13.Lineweight = Lineweight.W25;
            line13.Linetype = Linetype.DashDot;
            dxf.AddEntity(line13);

            var polyline10 = Pus.AddPointsToLwPolyLine(v20, v21, v22, v23);
            fun.PolyFill(dxf, polyline10, 0.03, refin);
            var polyline11 = Pus.AddPointsToLwPolyLine(v24, v25, v26, v27);
            fun.PolyFill(dxf, polyline11, 0.03, refin);
            var polyline12 = Pus.AddPointsToLwPolyLine(v28, v29);
            polyline12.Vertexes[0].Bulge = Math.Tan(122 * Math.PI / 180 / 4);
            fun.PolyFill(dxf, polyline12, 0.03, refin);




            double k;
            if (p == 2.5)
            {
                k = 5;
            }
            if (p == 2)
            {
                k = 5;
            }
            else
            {
                k = 10;
            }
            var a0 = fun.Polar(v1, -90 * Pi / 180, 3.5 * H);
            var a9 = fun.Polar(a0, 0, (l - le) / 2 * k);
            var a1 = a9;
            var a2 = fun.Polar(a1, 0, p / 8 * k);
            var a3a4 = new Vector2(a2.X + l1 * k, a2.Y + h4 * k);
            var a3 = fun.Polar(a3a4, 90 * Pi / 180 + γ, r * k);
            var a4 = fun.Polar(a3a4, 90 * Pi / 180 - γ, r * k);
            var a5 = fun.Polar(a2, 0, L * k);
            var a6 = fun.Polar(a5, 0, p * 1 / 8 * k);
            var a7 = fun.Polar(a3a4, 90 * Pi / 180, 5 * r * k);
            var a8 = fun.Polar(a3a4, -90 * Pi / 180, 20 * r * k);
            var a10 = fun.Polar(a0, -90 * Pi / 180, 0.195 * (H - h1) * k);

            var line14 = new Line(a1, a2);
            var line15 = new Line(a2, a3);
            var line16 = new Line(a4, a5);
            var line17 = new Line(a5, a6);
            var line18 = new Line(a7, a8);
            var arc2 = new Arc(a3a4, r * k, 90 - γ * 180 / Pi, 90 + γ * 180 / Pi);







            double o = 4;
            int o1;
            o1 = (int)o;
            Console.WriteLine("value:" + o1.ToString());

            Line[] linepoarra1 = new Line[1000];
            linepoarra1 = fun.arrayrline(line14, o1 + 1, 2, p * k, 10);
            for (int i = 1; i <= o1; i++)
            {
                fun.drawBline(dxf, linepoarra1[i], 0.2, contour);
            }
    ;
            Line[] linepoarra2 = new Line[1000];
            linepoarra2 = fun.arrayrline(line15, o1 + 1, 2, p * k, 10);
            for (int i = 1; i <= o1; i++)
            {

                fun.drawBline(dxf, linepoarra2[i], 0.2, contour);
            }
    ;
            Line[] linepoarra3 = new Line[1000];
            linepoarra3 = fun.arrayrline(line16, o1 + 1, 2, p * k, 10);
            for (int i = 1; i <= o1; i++)
            {

                fun.drawBline(dxf, linepoarra3[i], 0.2, contour);
            }
    ;
            Line[] linepoarra4 = new Line[1000];
            linepoarra4 = fun.arrayrline(line17, o1 + 1, 2, p * k, 10);
            for (int i = 1; i <= o1; i++)
            {
                fun.drawBline(dxf, linepoarra4[i], 0.2, contour);
            }
    ;
            Line[] linepoarra6 = new Line[1000];
            linepoarra6 = fun.arrayrline(line18, o1 + 1, 2, p * k, 10);
            for (int i = 1; i <= o1; i++)
            {

                linepoarra6[i].Layer = center;
                linepoarra6[i].Lineweight = Lineweight.W25;
                linepoarra6[i].LinetypeScale = 0.25;
                linepoarra6[i].Linetype = Linetype.DashDot;
                dxf.AddEntity(linepoarra6[i]);
            }
    ;
            Arc[] linepoarra5 = new Arc[1000];
            linepoarra5 = fun.arrayrarc(arc2, o1 + 1, 2, p * k, 10);
            for (int i = 1; i <= o1; i++)
            {
                fun.drawBArc(dxf, linepoarra5[i], 0.2, contour);
            }
    ;
            var polyline13 = Pus.AddPointsToLwPolyLine(a9, a0, a10);
            fun.PolyFill(dxf, polyline13, 0.2, contour);

            var a11 = fun.Polar(a7, 0, 3.5 * p * k);
            var a12 = fun.Polar(a8, 0, 3.5 * p * k);
            var a13 = fun.Polar(a11, 0, 0.1);
            var a14 = fun.Polar(a12, 0, 0.1);
            Line line19 = new Line(a11, a12);
            line19.Layer = center;
            line19.Lineweight = Lineweight.W25;
            line19.Linetype = Linetype.DashDot;
            dxf.AddEntity(line19);
            Line line20 = new Line(a13, a14);
            line20.Layer = center;
            line20.Lineweight = Lineweight.W25;
            line20.Linetype = Linetype.DashDot;
            dxf.AddEntity(line20);


            //标注
            DimensionStyle dimensionStyle = fun.DimStyle(true);
            DimensionStyle dimensionStyle2 = fun.DimStyle(false);



            if (le == l)
            {
                //L
                var dim2 = new LinearDimension(new Line(v0, v3), offset, 0, dimensionStyle);
                dim2.UserText = "INSL=" + l / scale;
                dxf.AddEntity(dim2);
            }
            else
            {
                //Le
                var dim1 = new LinearDimension(new Line(v1, v2), offset , 0, dimensionStyle);
                dim1.UserText = "Le=" + le / scale;
                dxf.AddEntity(dim1);
                //L
                var dim2 = new LinearDimension(new Line(v0, v3), offset*2, 0, dimensionStyle);
                dim2.UserText = "INSL=" + l / scale;
                dxf.AddEntity(dim2);
            }
            //h
            var dim3 = new LinearDimension(new Line(v16, v17), offset + v11.Y - v17.Y, 0, dimensionStyle2);
            dim3.UserText = "S1=" + h / scale;
            dxf.AddEntity(dim3);
            //h1
            var dim4 = new LinearDimension(new Line(a2, fun.Polar(a3a4, 90 * Pi / 180, r * k)), offset + Math.Abs(a2.X - a3a4.X) / 2, 90, dimensionStyle2);
            dim4.UserText = "POPT=" + h1 / scale;
            dxf.AddEntity(dim4);
            //P
            var dim5 = new LinearDimension(new Line(fun.Polar(a3a4, 90 * Pi / 180, r * k), fun.Polar(fun.Polar(a3a4, 90 * Pi / 180, r * k), 0, k * p)), offset, 0, dimensionStyle);
            dim5.UserText = "TP=" + p / scale;
            dxf.AddEntity(dim5);

            fun.jdbz1(dxf, new Line(a3, a2), new Line(a4, a5), offset * 2 + a3.Y - a2.Y, "PNA=" + β * 180 / Pi + "°", 1);

            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            Vector2 p0 = new Vector2(0, 0);

            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - offset * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }

            fun.SetLayer(dxf);
            fun.SetByLayer(dxf);

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
            Console.WriteLine("生成DXF文件" + path);
        }



    }
}
